Customize your excerpts
May
08
2006

In Wordpress (at least as far as I know – please correct me if I’m wrong) there are two functions that allow you to output your post content.

These functions are:

  • the_content (to which certain parameters can be passed). This function will output images, links…basically everything as you typed it in your post.
  • the_excerpt (to which no parameters can be passed). This function will output the post excerpt if there is one or it will output up to the first 55 words of your post content in a pure text form.

As you will have noticed I use both these functions here at renet@web. I use the_content to output the latest post and then the_excerpt to display the next 4 posts.

There are two things that I never liked with the function the_excerpt:

  • The post excerpt displayed terminates with the characters [...]
  • The length of the post excerpt is 55 words long and I never knew where that value could be changed

But despair no more, thanks to John Wrana a cure is at hand and in fact full credits are given to him for coming up with this trick of sorts. I should also warn you that if you do not understand what is indicated below, then you should not attempt to do this at home (then again maybe it’s my accent that makes it hard to understand) – this implies changing standard Wordpress files – proceed at your own risk.

My comprehension of German is a bit dodgy (haven’t been using it for quite some time), but what I could make in John’s post is that we need to change a bit of code in the file functions-formatting.php which you should find in the wp-includes folder of your Wordpress installation. What you need to do is to, in that file find the function wp_trim_excerpt():.

Bearing in mind what I said above, in that function I changed two things:

    A) The number of words displayed in the post excerpt.

  1. Change in the line where it says:
  2. $excerpt_length = 55;
  3. the number of words you want to see in your excerpt.
  4. Change the value ‘55′ to whatever you want.
    B) The standard ending characters [...] in the post excerpt.

  1. Change in the line where it says:
  2. array_push($words, '[...]');
  3. The characters [...] to whatever you want.
  4. You may decide to just change it to something like –> or or >>>

Before, I press this post, I should also point out that Chris J. Davis has written a wonderful post where he explains how to customize post excerpt using a more sophisticated method.

5 Responses to “Customize your excerpts”

  1. Gravatar of Oliver Zheng Oliver Zheng

    Or you could write an excerpt ;)

    I’m doing it the hard way. Using the more thing, and custom fields to achieve the effect so certain templates recognize different content. This way seems a lot easier, but it cuts off words.

  2. Gravatar of Pascal Pascal

    Oliver, how are you going to do it? I mean is it going to be in the form of a plugin or are you going to hack the wordpress code? Sounds promising.

  3. Gravatar of Oliver Zheng Oliver Zheng

    I have the “” at the end of where I want it in a post, and if indeed a post is long and needs to be shortened, it’s given a custom field as well. That way, the templates can recognize when to display the whole post or just everything before , based on the custom field.

    It’s kind of tedius, but I don’t mind :)

  4. Gravatar of Jeremy Jeremy

    Hey there – Nice posting!
    I am curious.. I found this post through http://www.chrisjdavis.org/2006/05/06/custom-excerpts-for-wordpress/

    Question: Were you able to get Chris’s method to work for you as well?

  5. Gravatar of Pascal Pascal

    Hi Jeremy.
    To be honnest I did not even try to implement Chris’s method. I found his post after having done my changes.
    Did you have a crack it?

Leave a Reply



Other entries you might like

You only need to go through the forums on SDN to realise that there are people out there that actually write programs or develop LSMW’s to upload Planned Independent Requirements (PIR) into SAP. Whilst I am sure that there are many valid reasons for wanting to develop your own upload programs, it is a shame [...]

Read more


This is really a quick tip that I’m posting more for me, but which I thought I’d share with the rest of the community.
If you are using the Service Desk functionality of Solution Manager, you may know that it is possible to create support requests right from your satelite SAP system. This is a really [...]

Read more


What I will explain here is particularly useful if you are using SAP Solution Manager, but it could also be applied to SAP CRM.
Solution Manager offers a very powerful functionality in that which is Service Desk. However I think that you are missing an important aspect of it if you do not set up automatic [...]

Read more


The details herein contained in this post relate to the solution manager VAR scenario – i.e your organisation acts as a service desk for your SAP customers. Whilst some of the concepts explained here might be of use to a CRM consultant, they are first and foremost destined for Solution Manager consultants setting up their [...]

Read more


According to Wikipedia, “Rich Internet Applications are web applications that have most of the characteristics of desktop applications, typically delivered by way of standards based web browser plug-ins or independently via sandboxes or virtual machines”. I don’t think that this definition does do it any justice – I think that RIA’s are:

Applications that offer a [...]

Read more