We know that meta description is part of good SEO practices and if you don’t have a compelling meta description for your blog posts, pages or custom post type posts then your site might be lacking and losing a lot of potential from search. So, I have decided to write an article about automatically limiting post meta description in WordPress Yoast plugin because we know that search engine cuts off the meta description after 170 characters but to make our website page keyword density free and to prevent keyword stuffing you might want to limit post meta description in WordPress Yoast.

Post meta description in  WordPress

Post meta description in WordPress

Limit Post Meta Description in WordPress Yoast

Another reason, you might be using custom post fields and the description field may exceed the number of characters on the page meta description so in order to limit that post meta description in WordPress Yoast, just add the following code in your theme’s functions.php file:

function yoast_softstribe_trim_description( $str ) {
 return substr($str, 0, 170);
add_filter( 'wpseo_metadesc', 'yoast_softstribe_trim_description' );

Now, if you go to any post and right click on the page to view source or by inspect elements then you might find that your meta description in WordPress has been reduced automatically to 170 characters. Which makes perfect sense and no more keywords stuffing 🙂