Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Show Excerpt Without Tags Or Shortcodes */
- add_filter( 'get_the_excerpt', 'custom_get_the_excerpt_in_loop_helloadmin', 5);
- function custom_get_the_excerpt_in_loop_helloadmin( $text ) {
- $raw_excerpt = $text;
- /* You can change this condition. If you choose '' == $text, then will be excerpt for get_the_content('').
- Note: In this case "Excerpt" field on the "Edit Post" page must be empty, else function will be output contain
- of the "Excerpt" field and in some cases will work incorrect. Used condition '' == !$text allow create 2 different excerpt.
- First excerpt will used for output a content part (by default is 55 first words), without headers and their content,
- also tags too. Second excerpt from "Excerpt" field on the "Edit Post" page, can use for output its contain in the
- <decription> tag on the header. */
- if ( '' == !$text ) {
- // Retrieve the post content.
- $text = get_the_content('');
- //Remove shortcode tags from the given content.
- $text = strip_shortcodes( $text );
- $text = apply_filters('the_content', $text);
- $text = str_replace(']]>', ']]>', $text);
- // Regular expression that strips the header tags and their content.
- $regex = '#(<h([1-6])[^>]*>)\s?(.*)?\s?(<\/h\2>)#';
- $text = preg_replace($regex,'', $text);
- /* Change the excerpt word count. */
- $excerpt_word_count = 40;
- $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
- /* Change the excerpt ending. */
- /* Uncomment it and remove string $excerpt_end = ' ...'; if you need replace default [...] to link of current post
- global $post;
- $excerpt_end = '<a href="'. get_permalink($post->ID) . '">Read more...</a>';
- */
- $excerpt_end = ' ...';
- $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end);
- $excerpt = wp_trim_words( $text, $excerpt_length, $excerpt_more );
- }
- return apply_filters('wp_trim_excerpt', $excerpt, $raw_excerpt);
- }
- ?>
Add Comment
Please, Sign In to add comment