How to show the excerpts of articles on home, search and archive pages?

By default, WordPress excerpt feature removes all format and displays first 55 words of written article. For some SEO reasons, it is good to display excerpt on home and archive pages.

To enable excerpt feature on home and archive pages, open your index.php file and look for the following line.

<?php the_content(); ?>

replace it with;

<?php if ($single) { the_content(); } else { the_excerpt(); } ?>

This code will display post content only on individual post pages.

8 Responses for “How to show the excerpts of articles on home, search and archive pages?”

  1. Elizabeth says:

    I want to do this, but only on the archive and search pages, not the home page. Is there a way to adapt your method for this?

  2. Mehmet says:

    Yes Elizabeth,

    Look on your theme files to see archive.php and search.php files

    on both files replace the_content with the_excerpt

  3. Elizabeth says:

    Thank YOU! Worked like a charm, I figured they had to be an easy way to do this.

  4. J.D. Meier says:

    Is there a way to do this only for the “categories”, but not the home?

  5. Mehmet says:

    J.D,
    Use the same hack that I told above to Elizabeth, Make sure to edit following files

    archive.php
    category.php
    search.php

  6. J.D. Meier says:

    I was hoping so, but archive is for when you click archive links and search is for when you use the search form.

    Unfortunately, I don’t have a category.php or that would do the trick. Apparently you either have home.php and category.php, or you have index.php instead. I have index.php.

    I did come across the following code that looks like it should actually work when you replace the_content inside index.php:

    … but strangely, I still get full posts. It doesn’t generate an error, but I also don’t get excerpts when clicking categories. I’m wondering whether this code isn’t automatic excerpts and I’m supposed to do something extra.

  7. Mehmet says:

    JD,

    When you don’t have category.php, your browser looks for archive.php to use. If you change the content into excerpt in your archive.php that will do the trick

  8. J.D. Meier says:

    Sweet! That worked – thanks!

Leave a Reply

ADVERTISEMENT

Log in - BlogNews Theme by Gabfire themes