Skip to content

Instantly share code, notes, and snippets.

@paulcollett
Last active April 10, 2025 14:16
Show Gist options
  • Save paulcollett/4c81c4f6eb85334ba076 to your computer and use it in GitHub Desktop.
Save paulcollett/4c81c4f6eb85334ba076 to your computer and use it in GitHub Desktop.
Remove Yoast HTML Comments “This site is optimized with the Yoast WordPress SEO plugin”
// For Yoast SEO Plugin Version: 14.1+ add to your Wordpress Theme's functions.php...
// Remove All Yoast HTML Comments
// https://gist.github.com/paulcollett/4c81c4f6eb85334ba076
// Credit @devendrabhandari (https://gist.github.com/paulcollett/4c81c4f6eb85334ba076#gistcomment-3303423)
add_filter( 'wpseo_debug_markers', '__return_false' );
// For Yoast SEO Plugin Version: < 14.1 add to your Wordpress Theme's functions.php...
// Remove All Yoast HTML Comments
// https://gist.github.com/paulcollett/4c81c4f6eb85334ba076
// Credit @maxyudin (https://gist.github.com/paulcollett/4c81c4f6eb85334ba076#gistcomment-2937964)
add_action('wp_head',function() { ob_start(function($o) {
return preg_replace('/\n?<.*?yoast seo plugin.*?>/mi','',$o);
}); },~PHP_INT_MAX);
@maxyudin
Copy link

maxyudin commented Jun 7, 2019

Since plugin version 11 the original code breaks the Knowledge Graph & Schema.org contents (opening <script type='application/ld+json' tag disappears).
So, change preg_replace() pattern as follows. May be somebody have more elegant solution.

preg_replace('/\n?<.*?yoast seo plugin.*?>/mi','',$o);

@DennysDionigi
Copy link

DennysDionigi commented Aug 21, 2019

Hi all, I found this function which seems lighter than a "heavy" replace:

/**
 * Disable Yoast's Mark and its version.
 */
add_action( 'template_redirect', function () {
     if ( ! class_exists( 'WPSEO_Frontend' ) ) {
        return;
    }
    $instance = WPSEO_Frontend::get_instance();
     // make sure, future version of the plugin does not break our site.
    if ( ! method_exists( $instance, 'debug_love') ) {
        return ;
    }
    // ok, let us remove the love letter.
     remove_action( 'wpseo_head', array( $instance, 'debug_love' ), 2 );
}, 9999 );

Also please note that as said by @maxyudin , the previous code breaks the script tag, adding the printed code in the body.

@kangmis77
Copy link

Looks good.. thanks dude... I'll try... http://ideunik.com/

@jeremypetrequin
Copy link

jeremypetrequin commented Jan 2, 2020

The method seems to be called "debug_mark" in the latest version of Yoast,
So the adapted code of @DennysDionigi working for me on the last version is

/**
 * Disable Yoast's Mark and its version.
 */
add_action( 'template_redirect', function () {
	if ( ! class_exists( '\WPSEO_Frontend' ) ) {
		return;
	}
	$instance = \WPSEO_Frontend::get_instance();
	// make sure, future version of the plugin does not break our site.
	if ( ! method_exists( $instance, 'debug_mark') ) {
		return ;
	}
	// ok, let us remove the love letter.
	remove_action( 'wpseo_head', [ $instance, 'debug_mark' ], 2 );
}, 9999 );

@Ridys
Copy link

Ridys commented Feb 27, 2020

Thanks

@devendrabhandari
Copy link

devendrabhandari commented May 14, 2020

Now use the below code to remove Yoast HTML Comments from version 14.1
Yoast SEO Plugin Version: 14.1

add_filter( 'wpseo_debug_markers', '__return_false' );

@mohsinr
Copy link

mohsinr commented Jun 19, 2020

Now use the below code to remove Yoast HTML Comments from version 14.1
Yoast SEO Plugin Version: 14.1

add_filter( 'wpseo_debug_markers', '__return_false' );

Thank you! It works!

@f0rtisyy2019
Copy link

Now use the below code to remove Yoast HTML Comments from version 14.1
Yoast SEO Plugin Version: 14.1
add_filter( 'wpseo_debug_markers', '__return_false' );

Thank you! It works!

Also works for me. Thanks

@ulissse
Copy link

ulissse commented Sep 6, 2020

Hello,
It work but is it possible to get rid of all the spaces and tabulations?
Thank you.

@eduardsantamaria
Copy link

Now use the below code to remove Yoast HTML Comments from version 14.1
Yoast SEO Plugin Version: 14.1
add_filter( 'wpseo_debug_markers', '__return_false' );

Thank you! It works!

Also works for me. Thanks

Now use the below code to remove Yoast HTML Comments from version 14.1
Yoast SEO Plugin Version: 14.1

add_filter( 'wpseo_debug_markers', '__return_false' );

It Works! Thank you!

@justinrains
Copy link

Awesome! Thanks for the code. Much appreciated!

@jenkinstm
Copy link

Still works! Thank you.

@ikiyamay
Copy link

Still works! Thank you.

@freschstudio
Copy link

Still works in April 2025. 🙂

@nucklearproject
Copy link

Still works in April 2025. 🙂

In the latest versions of Yoast, the setting already includes the functionality to remove comments and other elements from the header.

@freschstudio
Copy link

Still works in April 2025. 🙂

In the latest versions of Yoast, the setting already includes the functionality to remove comments and other elements from the header.

Where is the setting exactly? Remove powered by HTTP header option under Crawl optimization doesn't remove this.

I'm on Yoast 24.8.1

@nucklearproject
Copy link

Still works in April 2025. 🙂

In the latest versions of Yoast, the setting already includes the functionality to remove comments and other elements from the header.

Where is the setting exactly? Remove powered by HTTP header option under Crawl optimization doesn't remove this.

I'm on Yoast 24.8.1

Sorry, I was wrong 😞 — there’s no option to remove comments, but I could swear it was there at some point 🤔. Now I’m left with doubts. I use Autoptimize and WP Super Cache; they remove all comments, including the “Powered by Yoast” one. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment