Tip: How to change the default Wordpress excerpt

Ever get tired of those nasty [...] ellipses that appear beneath your blog excerpts? I do. In this tutorial, I am going to show you how to change Wordpress’ default excerpt display without changing core Wordpress files.

Open up functions.php and add this code to the very bottom of the file:

<?php function gpp_excerpt($text) { return str_replace('[...]', '<br /><a href="'.get_permalink().'">Read More &rarr;</a>', $text); } add_filter('the_excerpt', 'gpp_excerpt'); ?>

The above code “filters” Wordpress’ default the_excerpt function and replaces it with our own gpp_excerpt function. We have just written a very simple plugin for Wordpress.

If, however, you are writing your own excerpts and want to add a Read More permalink, replace:

<?php the_excerpt(); ?>

with this:

<?php the_excerpt(); ?><span class="read_more"><a href="<?php the_permalink(); ?>">[ Read More &rarr; ]</a></span>

If you found this tutorial useful, consider subscribing to Graph Paper Press. You will get access to our support forum, where additional tutorials similar to this one are available to our subscribers.

32 Responses Comments RSS

  1. To which “functions.php” file should this code be added? To the one in “wp-includes” or the one in the theme folder?

    • You make the changes on the functions.php file in your theme folder. You should never touch the Wordpress files, unless you are a serious developer.

  2. Great–I’ll give it a try. Thanks!

  3. Very useful tips, thank you.

  4. Cool…thank you! Super easy, and it works! Now to make a widget that will do it… :)

  5. thanks, works like a charm, now my issue is to add post pic!

  6. I am not too good in coding. Now as you have told this function but can you also let know how we can change or customize the theme our way. Like if we want the menu bar to be in different way..

  7. Nice one, works a dream. Thank you.

  8. This is simple but useful tips, thanks.

  9. What a great site for info, I am a novice, The info gained here I can put in my log and reuse in time.Thank you

  10. As I learn more I will always remember that I started here. Thank you for all the info I can put it to use in my business plan.Our site please check us out

  11. Thank you for all the info

  12. Thanks for the nice information

  13. thanks for your article

    it is a nice blog

  14. This is very detailed. Thanks for teh screenshots.

  15. share this issue with us, thank you to my friends. Have very good information on this site.
    good work

  16. The community using, supporting and developing WordPress just has soooo much to offer. Simple things like this is a real treat to non-developer types like me, and to have figured it out on my own (using another platform without the enthusiast community to back it) would’ve been a big task. Thank you for saving us time (and indirectly, money)!!!

  17. Wow, that was easy. thank you.

  18. Thanks!
    How can I change the tag
    to something else like “read more”?

  19. Very useful tip that will come in very handy. Many Thanks

  20. Please HELP!!!

    I put this in the bottom of the functions.php but nothing happened so i put it up inbetween the very last arrow and question mark and my sites broken?

    http://www.commercialphotographystudiowales.co.uk

    it’s coming up blank and I can’t login via the /wp-admin either

    I’ve looked at the function.php in my ftp software but there seems to be far more stuff in there than there was when looking at it on internet through apperance/ editor on wordpress.

    please help

    Thank you very much!

  21. Thank you! That was an excellent tip.

  22. Yet another way. It’s tough to decide which to use, haha. This one does seem easy to implement tho. Thanks for the post

  23. Thanks!
    How can I change the tag
    to something else like “read more”

  24. Yes i think these codes will be useful for me . try it soon.

  25. Extremely helpful, thanks so much!

  26. After my installed excerpt plugin didn’t work, I use your code and it works like charms.. thank you

  27. Awesome… I’ve been looking for something like this for so long… I used it and works great. Thanks so much.

Trackbacks

  1. [...] Blog and tagged with excerpt, tutorial. You can follow any responses to this entry through the RSS 2.0 feed. ← [...]

  2. [...] however, you are writing your own excerpts Go to Source Share and [...]

  3. [...] if you just need to change the “[...]” to something of your choosing, using a simple function like this is probably a better option.  I used the funtion method on a website today – just popped the [...]

Leave a Reply