Remove Yoast SEO Comments in WordPress page source

Updated on October 13, 2021

Do you want to remove the comments printed by the Yoast SEO plugin in the page source? Well, this tutorial will explain how to remove Yoast SEO comments from WordPress pages. Yoast SEO is one of the popular WordPress plugins that lets you optimize your website with necessary keywords to improve search engine ranking. So if you want to improve your website’s position in search results, then I would strongly recommend Yoast SEO plugin. But for some reason, you might not want the plugin to leave comments in the page source. If you are someone like me who wants to remove those comments from the page sources, then here’s how you can do that.

Step 1: Copy the below code snippet.

For Yoast SEO plugin version less than 14.1, add the below code in functions.php

if (defined('WPSEO_VERSION')) {
 add_action('wp_head',function() { ob_start(function($o) {
return preg_replace('/\n?<.*?yoast seo plugin.*?>/mi','',$o);
 }); },~PHP_INT_MAX);
}

Thanks to paulcollett@github.

Update 13th October 2021: (Thanks to one of the readers who pointed out to update the code.)

For Yoast SEO plugin version 14.1+, add the below code in functions.php.

add_filter( 'wpseo_debug_markers', '__return_false' );

Step 2: Go to the WordPress theme directory and open functions.php the file. For example, public_html/wp-content/themes/mytheme/functions.php

Step 3: Paste the code to the end of the file.

Step 4: Save and exit.

Step 5: Load your WordPress site and right-click to view the page source. That’s it, the SEO comments are removed from the page source.

Was this article helpful?

Related Articles

Comments Leave a Comment

    1. Thanks for pointing it out. The code has been updated for version 14.1+

Leave a Comment