Back to Top

How to set word limit on the_content() in WordPress

Limit by words 'the_content' in WordPress

Sometimes, you can not limit the content by character or letter.It distracts the layout of content so you want to set word limit on the_content() in WordPress so content displaying the site looks pretty good.Well, In WordPress, we are using a the_content function to displaying the content of post or blog.So here we need to customize the_content function which we can do by applying the hook into it.Open theme’s file functions.php and place the following code into it.

You just need to copy and paste the above code and just change the $word_limit variable value to the desired limit you want.

Now, you are finished.If you have any query or any confusion then feel free to comment me.

Hope this post will helpful for you, waiting for your responses.Thanks for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (3)

  1. It works but does not work. It also effects when you click on the post (in single.php).

    Also, I want to ask how to add … or read more using this snippet.

  2. This one works:

    function limit_the_content($content){
    $word_limit =90;
    $words = explode(‘ ‘, $content);
    if (!is_single()) {
    return implode(‘ ‘, array_slice($words, 0, $word_limit)).” …”;
    } else {
    return $content;

  3. Antonio Rodriguez Olmos says:

    Thank you Lal! Yours is the only method that works đŸ˜€

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

The Readers’ Poll – June 2012

Posted on 6 years ago


Overview of ECMAScript 6 new Features

Posted on 10 months ago


Storing Objects in Html5 Local Storage

Posted on 2 years ago


How to Use PHP Sessions to Store Data

Posted on 2 years ago