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.

Privacy Preference Center