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.
1 2 3 4 5 6 7 8 | add_action('the_content','limit_the_content'); function limit_the_content($content){ $word_limit =10; $words = explode(' ', $content); return implode(' ', array_slice($words, 0, $word_limit)); } |
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 (5)