Wordpress how to show excerpt without editing themes


1 Votes, Rating: 51 Star2 Stars3 Stars4 Stars5 Stars

Tags: , ,

WP How to change content to brief without editing themes

For changing your content to brief content, you dont need to edit your theme each pages. most blog owner does this  way. but now here im giving you solution to show brief on your main pages like index, search, category without editing those pages one by one.

So here is the solution

What you need to do just open your theme function.php page and add below codes.

<blockquote>
add_filter('the_content', 'Show-excerpts');
 
function Show-excerpts($content = false) {
 if(is_front_page() || is_archive() || is_search()) :
  global $post;
  $content = $post-&gt;post_excerpt;
  if($content) :
   $content = apply_filters('the_excerpt', $content);
  else :
   $content = $post-&gt;post_content;
   $excerpt_length = 55; ############## add your word count
   $words = explode(' ', $content, $excerpt_length + 1);
   if(count($words) &gt; $excerpt_length) :
    array_pop($words);
    array_push($words, '...');
    $content = implode(' ', $words);
   endif;
   $content = '&lt;p&gt;' . $content . '&lt;/p&gt;';
 
  endif;
 endif;
 return $content;
 
}</blockquote>

all done,

Share/Save/Bookmark

Leave a Reply