Showing Excerpts in WordPress Home, Search, Tag and Archive Pages


Showing only the post excerpts in home, search, tag or archive pages is useful if your posts are particularly long. The readers won’t have to scroll down the page for a particular post.

You can edit the template file content.php (recommended using a child-theme), to navigate to this line:

1
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<?php if ( is_search() ) : // Only display Excerpts for Search ?>

and replace it with:

1
<?php if ( is_search() || is_home() || is_tag() || is_category() || is_archive() ) : // Only display Excerpts for Search ?>
<?php if ( is_search() || is_home() || is_tag() || is_category() || is_archive() ) : // Only display Excerpts for Search ?>

The function is_archive() checks if current page is is a Category (is_category), Tag (is_tag), Author or a Date based pages. The next line uses the_excerpt() to display short excerpt instead of the_content

If you want to show a link at the end of excerpt, then you can edit the functions.php (preferably in child-theme), add the following to the end of the file:

1
2
3
4
5
6
7
8
9
10
11
// Remove the ... from excerpt and change the text
function change_excerpt_more()
{
  function new_excerpt_more($more)
    {
    // Use .read-more to style the link
      return '<span class="continue-reading"> <a href="' . get_permalink() . '">Continue Reading »</a></span>';
    }
  add_filter('excerpt_more', 'new_excerpt_more');
}
add_action('after_setup_theme', 'change_excerpt_more');
// Remove the ... from excerpt and change the text
function change_excerpt_more()
{
  function new_excerpt_more($more)
    {
    // Use .read-more to style the link
      return '<span class="continue-reading"> <a href="' . get_permalink() . '">Continue Reading »</a></span>';
    }
  add_filter('excerpt_more', 'new_excerpt_more');
}
add_action('after_setup_theme', 'change_excerpt_more');

This modification does not alter the output in the feed. To show the excerpt in the feed, you will need to go to wordpress settings, reading settings and set “For each article in a feed, show” to “Summary” instead of “Full Text”. However, this does affect the posts in other pages as well (home, archive).

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
334 words
Last Post: How to Connect to Monitor using USB on Nokia Lumia 635 Smart Phone?
Next Post: Anker Wireless Bluetooth Speaker

The Permanent URL is: Showing Excerpts in WordPress Home, Search, Tag and Archive Pages

Leave a Reply