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:

    add_action(‘the_content’,’limit_the_content’);
    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

Welcome to Creative Dev

Posted on 6 years ago

Bhumi

Introduction to Table Partitioning in Oracle

Posted on 12 months ago

Bhumi

How to use Session in Joomla

Posted on 6 years ago

Bhumi

How to use jQuery UI tabs in a WordPress?

Posted on 5 years ago

Bhumi