Categories
WordPress

HOW TO SET WORD LIMIT ON THE_CONTENT() IN WORDPRESS

Sometimes, you can’t limit the information by character or letter.It distracts design of content would you like to set word limit around the_content() in WordPress so content displaying the website looks very good.

HOW TO SET WORD LIMIT ON THE_CONTENT() IN WORDPRESS

Learn More: HOW TO INSERT POST PROGRAMMATICALLY IN WORDPRESS?

Well, In WordPress, we’re utilizing a the_content function to displaying the information of publish or blog.Here we have to personalize the_content function which are going to by making use of the hook in it. Open theme‚Äôs file functions.php and put the next code in it.

add_action( 'the_content', 'modify_the_content' );
function modify_the_content( $content ) {

    $word_limit =10;
    $words = explode(' ', $content);
    return implode(' ', array_slice($words, 0, $word_limit));

}

You need to simply copy the above mentioned code and merely alter the $word_limit variable value towards the preferred limit you would like.

Now, you’re finished. For those who have any query or any confusion then you can comment me.

Hope this publish will useful for you personally, awaiting your responses.Thank you for studying and you can share your ideas! Remember to follow along with us on Twitter or Subscribe us to obtain the Latest Updates.

By Ankit Panchal

I'm a WordPress consultant and Web developer. I like solving digital problems which help your business grow. I specialize in WordPress plugin development and frontend development and am available for hire.