Guest User

Untitled

a guest
Feb 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <?php
  2. /* Show Excerpt Without Tags Or Shortcodes */
  3. add_filter( 'get_the_excerpt', 'custom_get_the_excerpt_in_loop_helloadmin', 5);
  4. function custom_get_the_excerpt_in_loop_helloadmin( $text ) {
  5. $raw_excerpt = $text;
  6. /* You can change this condition. If you choose '' == $text, then will be excerpt for get_the_content('').
  7. Note: In this case "Excerpt" field on the "Edit Post" page must be empty, else function will be output contain
  8. of the "Excerpt" field and in some cases will work incorrect. Used condition '' == !$text allow create 2 different excerpt.
  9. First excerpt will used for output a content part (by default is 55 first words), without headers and their content,
  10. also tags too. Second excerpt from "Excerpt" field on the "Edit Post" page, can use for output its contain in the
  11. <decription> tag on the header. */
  12. if ( '' == !$text ) {
  13. // Retrieve the post content.
  14. $text = get_the_content('');
  15. //Remove shortcode tags from the given content.
  16. $text = strip_shortcodes( $text );
  17. $text = apply_filters('the_content', $text);
  18. $text = str_replace(']]>', ']]>', $text);
  19. // Regular expression that strips the header tags and their content.
  20. $regex = '#(<h([1-6])[^>]*>)\s?(.*)?\s?(<\/h\2>)#';
  21. $text = preg_replace($regex,'', $text);
  22. /* Change the excerpt word count. */
  23. $excerpt_word_count = 40;
  24. $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
  25. /* Change the excerpt ending. */
  26. /* Uncomment it and remove string $excerpt_end = ' ...'; if you need replace default [...] to link of current post
  27. global $post;
  28. $excerpt_end = '<a href="'. get_permalink($post->ID) . '">Read more...</a>';
  29. */
  30. $excerpt_end = ' ...';
  31. $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end);
  32. $excerpt = wp_trim_words( $text, $excerpt_length, $excerpt_more );
  33. }
  34. return apply_filters('wp_trim_excerpt', $excerpt, $raw_excerpt);
  35. }
  36. ?>
Add Comment
Please, Sign In to add comment