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.

Newsletter
Join over 280,000 independent website owners

Get free themes, plugins, and discounts
in our monthly email.

We guarantee 100% privacy. Your information will not be shared.

This entry was posted in Blog and tagged , . Bookmark the permalink.

Posted by , at Graph Paper Press

Thad is the founder of Theme.Works and Graph Paper Press. Previously, he produced online multimedia and documentary projects for USA Today including the inauguration of President Barack Obama and many others. He lives in Brooklyn, NY with his wife Abby.

  • Google
  • Blog
  • Instagram

72 thoughts on “Tip: How to change the default WordPress excerpt”

    1. 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.

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

    1. 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. Cool…thank you! Super easy, and it works! Now to make a widget that will do it… 🙂

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

  4. 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..

  5. 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..

  6. 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

  7. 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

  8. 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)!!!

  9. 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)!!!

  10. 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!

  11. 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!

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

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

  14. Hi,

    I applied the span version of your recommendation and it does as you suggest EXCEPT that the original (…) is still there (and not hyperlinked).

    Any suggestions?

  15. Hi,

    I applied the span version of your recommendation and it does as you suggest EXCEPT that the original (…) is still there (and not hyperlinked).

    Any suggestions?

  16. Parse error: syntax error, unexpected ‘<' in /var/www/virtual/kujo.is/htdocs/wp-content/themes/application/functions.php on line 210 trololol

  17. okuduğum bir kitaptan etkilendim ve tasarım yaptım. çok başarılıydı diye düşünürken herkes beğendi. mutluyum 🙂

Leave a Reply

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