Use Post Excerpts Everywhere

By Daniel Scocco

Google and other search engines penalize sites that have duplicated content. That refers not only to two different sites with the same content but also for a single website that has the same content repeated on many different internal pages.

Once you publish a post on your blog this content will be indexed from the single post page. Many templates, however, will also publish that same post on several other pages like category pages, yearly archives, monthly archives, daily archives, search results and so on.

In order to make sure that you are not incurring any penalty for duplicated content you should make all those pages display only post excerpts instead of full posts. You could even display post excerpts on the Homepage, but make sure your readers would be fine with that first (read more about this on the article “Post Excerpts on the Homepage?”).

The first thing you need to do is to check whether your theme is displaying full posts on the wrong places. Check the category pages, run a search to see how results are displayed and check all the archive pages (add a /2007/ to your blog address and see how the posts are displayed).

If your blog is displaying full posts on pages other than the single post page you will need to fix that. WordPress themes usually have the index.php or archive.php file governing how posts are displayed (but could another file). You are looking for something like this:

<?php if (is_category()) { ?>
<div class="page-title">
<h2><?php _e('Archive for'); ?> <?php echo single_cat_title(); ?></h2>
</div>
<?php } elseif (is_search()) { ?>
<div class="page-title">
<h2><?php _e('Search Results'); ?></h2>
</div>
<?php } ?>

Once you find that file you will need to identify where the WordPress Loop starts, which is something like this:

<?php while (have_posts()) : the_post(); ?>

Inside the Loop there is a line making your theme display full posts:

<?php the_content(__('Read the rest of this entry »')); ?>

We could just change the line above with the code for post excerpts, but that would make the exercpts to be displayed everywhere including on the Homepage and on the single post pages.

The solution is to use IF clauses to make sure that only specific pages will display excerpts. Basically you want to create an IF for every page type that is supposed to display excerpts, and at the end you will insert an ELSE to make sure that all other pages will display full posts. Here is how the code will look like:

<?php if (is_search()) { ?>
<?php the_excerpt() ?>
<?php } elseif (is_category()) { ?>
<?php the_excerpt() ?>
<?php } elseif (is_year()) { ?>
<?php the_excerpt() ?>
<?php } elseif (is_month()) { ?>
<?php the_excerpt() ?>
<?php } elseif (is_day()) { ?>
<?php the_excerpt() ?>
<?php } else { ?>
<?php the_content('Read the rest of this entry »'); } ?>



Related Articles

Please install the YARPP plugin

Share

43 Responses to “Use Post Excerpts Everywhere”

  • Bang Kritikus

    I dont know about php, please give me a tutorial link

Comments are closed.