Use Excerpt in Index, Category, Tag and Arhieve Pages for WordPress

Posted on In Web

By default, all of the content of the post is shown in index, category, tag, archive and search pages. This is duplicate contents which may cause search engine penalty. The better way is using excerpt in index, category, tag and arhieve pages. By doing this the duplication can be avoided and the blog is optimized. After using the excerpt the blog will be much faster.

If an explicit excerpt to a post is not provided by the author, the first 55 words of the post’s content are used for excerpt. And the excerpt end with […], which is not a “read more” link. For convenient, we may add a “read more” link at the end of the excerpt for the reader.

The method for using excerpt in WordPress

Replace the_content() function with the_excerpt() when the post is on archive (tested by is_archive()) and category (is_category()) pages and index (is_home()) page in WordPress themes. But WordPress has another function named is_singular() to determine whether this is a page or a single post. So the easiest way is use is_singular() to test whether it is the page or single post. If the function returns true, display the whole content of the post, otherwise display the excerpt.

First find the theme used under wp-content/themes. The php file for index is index.php or home.php. Try to find this sentence in the index php file:

<?php the_content(); ?>

Then replace it with:

<?php if(is_singular()) {
 the_content((__( '&raquo; Read more: ', 'default')) . the_title('', '', false));
} else {
 the_excerpt();
 _e('<div><div><a href="', 'default');
 the_permalink();
 _e('">&raquo;&raquo;&raquo; Read More of "', 'default');
 the_title();
 _e('"</a></div></div>', 'default');
} ?>

Maybe files such as archive.php should also be changed if the archives, categories and tags are displayed using different method.

It’s the same for the search pages. The only difference is the php file for search pages is search.php. Find the relevant php sentence and replace it with the codes listed above.

The is very good for SEO. After doing this the search engine will no long see a lot of duplicated contents in the blog and it will index much more pages.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

4 comments

  1. Hi my family member! I want to say that this article is amazing, nice written and include almost all significant infos. I would like to look extra posts like this.

Leave a Reply

Your email address will not be published. Required fields are marked *