Oct
28
2009

Quick & Easy Excerpt Mods Coming in WordPress 2.9

by   |  Posted in Tutorials  |  13 comments

I just stumbled across these two little pieces of code and thought that they might be useful to some people out there who want to mess around with the default settings for the_excerpt() function in WordPress. The first one gives you the power to change the number of words displayed by the function the_excerpt(), and yes, you can have more than 55 words. The second piece of code allows you to change the trailing [...] that appears at the end of your excerpt.

Both features are set to be added to version 2.9 of WordPress, but the first currently works in version 2.8.5. Just add these to your theme’s functions.php file.

1
2
3
4
function new_excerpt_length($length) {
	return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');

Change the number “20″ to whatever number you want.

1
2
3
4
function new_excerpt_more($more) {
	return '[.....]';
}
add_filter('excerpt_more', 'new_excerpt_more');

Change “[.....]” to whatever you want.

About the author:

A freelance web developer living in Montreal who spends most of his time writing for this site and building Premium themes for WordPress. You can find him on Twitter @bavotasan.

Site5 Affiliate Link
If you liked this, please share it.

Tags: , , , , , , , , , , , , , , , , , ,

Short URL: http://bit.ly/b9bYoD

Discussion 13 Comments

  1. Carlos on October 28, 2009 at 10:41 pm

    Currently what I do is use the

    <!--more-->

    code to limit what I want as a teaser read of the post and like most times I have to go back and forth adjusting the limit. So with the use of the Excerpt function, would this be a more sensible method?

    • c.bavota on October 29, 2009 at 12:09 am

      This would make every excerpt the same length. But the thing about the excerpts is that they are stripped of all tags so that might not be what you want.

    • Carlos on October 29, 2009 at 2:47 pm

      Ahh yea I wouldn’t want that. I’ll do some testing on that this weekend and see what results I come up with using this function. I also found your Limiting the Number of Words in Your Excerpt or Content in WordPress article which has spurred some ideas that relate to the Excerpt function.

  2. Dan on February 2, 2010 at 10:33 am

    This method does not work.

    • c.bavota on February 2, 2010 at 11:34 am

      Are you using WordPress 2.9?

    • Caroline on April 27, 2011 at 9:34 pm

      I’m impressed! You’ve managed the almost ipmosilsbe.

  3. Sid Randolph on June 25, 2010 at 3:26 pm

    Will this not work in WordPress 3.0?

    • c.bavota on June 25, 2010 at 7:49 pm

      It works in 3.0.

  4. Paul on July 22, 2010 at 10:56 pm

    Thanks so much… found your solution via google (‘limit words in wordpress excerpt’) search and it worked very well!

    Kudos.

  5. faisal on August 27, 2010 at 5:24 am

    Hello,

    Read more coming in one news only not in second and also it is not linking to anything?

    I used this code

    <?php the_date(); echo "”; ?>

    <?php echo excerpt(25); echo "”;?>

  6. faisal on August 27, 2010 at 5:25 am

    sorry here is code again

     
     
    &lt;?php the_date(); echo &quot;"; ?&gt;
     
    &lt;?php echo excerpt(25); echo &quot;";?&gt;
  7. Wendy on December 10, 2010 at 12:57 am

    I only used the first one as I don’t mind the trailing at the end of excerp. It works great! I am not a programmer/coder and the type who gets stuck at every turn it gets so bad… But this worked instantly, so pleasantly surprised! Things were overlapping on my homepage but now it’s perfect. Thanks a million!