1. Home
  2. WordPress
  3. Remove Yoast SEO Comments in WordPress page source

Remove Yoast SEO Comments in WordPress page source

Do you want to remove the comments printed by Yoast SEO plugin in page source? Well, this tutorial will explain how to remove Yoast SEO comments from WordPress pages. Yoast SEO is one of the popular WordPress plugin that lets you to 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 page source, then here’s how you can do that.

Step 1: Copy the below code snippet.

if (defined('WPSEO_VERSION')) {
 add_action('wp_head',function() { ob_start(function($o) {
 return preg_replace('/^\n?<!--.*?[Y]oast.*?-->\n?$/mi','',$o);
 }); },~PHP_INT_MAX);
}

Thanks to paulcollett@github.

Step 2: Go to WordPress theme directory and open functions.php 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 page source.┬áThat’s it, the SEO comments are removed from the page source.

Updated on January 17, 2018

Was this article helpful?

Related Articles

Leave a Comment