I write about design, music, games and just about anything else that interests me. Stick around for some freebies too!

Custom Excerpt Length in WordPress

Posted on Monday, October 14th, 2013 - Tutorials & Tips

When designing custom themes or editing existing themes in WordPress, sometimes the native excerpt length isn’t quite suited to the design and layout.  This is actually a really simple fix for anyone needing something that isn’t too hacky and wants ultimate control over the length of the excerpt.  All you have to do is first, paste the following code into your functions.php file:

Once this is done, you can just use the following code in any of your template files, replacing the number 25 with whatever number you like.  See, simples!  You can also use this with the content as well as the excerpt, all you have to do is change the word ‘excerpt’ below to ‘content’.

Let me know in the comments below what you think of this method, and if you have a better way of doing this then please post your suggestions below too!

Share Your Thoughts

  • Bill Gilmore

    Pretty sweet, easier than the last method I found

    • Yeh it’s pretty nice, plus you can just take lines 2-12 if you only want to option of shortening the excerpt, likewise lines 14-26 if you only want the content.

  • Lance

    Amazing bit of code. I also took the excerpt function, replaced $excerpt with $title, and changed get_the_excerpt to get_the_title. Works perfectly to create a custom title length. Thank you again.

    • Good call Lance. This can be used with almost any WordPress function that outputs a string – I’ve used it myself to create some shorter titles in the past and it works like a charm.