Advertisement
maxworkingwell

Rewrite the excerpt settings

Nov 22nd, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. // Rewrite the excerpt settings
  2. function get_excerpt($text, $post_id) {
  3.     $post_content = get_post($post_id);
  4.     $text = $post_content->post_content;
  5.     $text = apply_filters('the_content', $text);
  6.     $text = str_replace('\]\]\>', ']]>', $text);
  7.     $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  8.     $text = strip_tags($text, '<p><a><img><ul><li><strong><br>');
  9.     $excerpt_length = 50;
  10.     $words = explode(' ', $text, $excerpt_length + 1);
  11.     if (count($words)> $excerpt_length) {
  12.             array_pop($words);
  13.             array_push($words, '...');
  14.             $text = implode(' ', $words);
  15.             $text = force_balance_tags( $text );
  16.     }
  17.  
  18.     return $text;
  19. }  
  20. add_shortcode('full-post-excerpt', 'get_excerpt');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement