Display post excerpt in recent posts widget in WordPress

Everytime we upgrade to the latest version of WordPress (currently 2.8.1) we lose a bit of customising. Whether it’s the value of the search button in the search widget (hidden because of IE6’s and IE7’s disability to apply text-indent to form buttons) or the excerpt of our posts displayed in the widget on most of the pages disappears. For future reference and for people who don’t want to be searching for widgets to do that for them I’ve decided to describe how to quickly and easily get the job done – yourself!

First of all: the following only applies to WordPress 2.8 and later.

  1. Open the default-widgets.php (to be found in the “wp-includes” folder of your blog)
  2. Insert “<?php    the_excerpt();    ?>” on line 553 (straight after
    <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
  3. Save
  4. Refresh a page with the widget displayed

Whilst I did look into installing a widget that would do this for me automatically I couldn’t find one that’d satisfy me. If you are using one please let me know which one, I’d love to consider automating the process. The reason I wrote this post is also because Google didn’t offer accurate enough or up-to-date results.

Helpful? Drop me a line… :)

Bookmark and Share

11 Responses to “Display post excerpt in recent posts widget in WordPress”

  1. etuan says:

    You made my night!!

    I have been struggling with this for hours and you just solved it for me. You are a kind an generous person to share this with the world!

    Thank you so much!

  2. Pleasure! Glad it helped, it was bugging me all the time (maintaining dozens of WP sites) and the information was nowhere to be found. Really pleased someone else benefits too!

    All the best,
    Martin

  3. Beth says:

    Dude,

    Awesome! Such a simple solution! This beats the heck out of having to add a big ol’ plug-in to solve a minor problem. Greatly appreciated.

    –M. Beth Spicer

  4. Pleasure Beth, glad it helped! :)

    Martin

  5. Dave says:

    I’d like to add my thanks for this solution, which I can report works with the Thesis theme. Great job, Martin!

  6. dainys says:

    seems it doesn’t work on wp 2.8.6

  7. Hi Dainys,

    shouldn’t really say, but just for you, I have just upgraded to 2.8.6 and applied the aforementioned fix. It works (as the front page of my half-finished website) will testify! Make sure you read the instructions correctly, I am happy to confirm I got it working my end!

    All the best,
    Martin

  8. Flint says:

    Unfortunately I’m using 2.8.6 too and it didn’t do anything. Is there anything else that needs to be in the PHPs or anything to toggle on or off before adding that tag?

  9. I upgraded to 2.9 (direct from 2.6), and reinstated the code. It’s working beautifully. Are you sure you’re using the standard “recent posts” widget on your page?

  10. I can confirm now that we have upgraded our blog to 2.9 -> it is still working beautifully and 100%. I wish WP people made this as an option in the widget rather than us having to go around it like we do…

    Anywho: all the best in 2010 to everybody! :)

Leave a Reply