Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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);
@Marinski

This comment has been minimized.

Copy link

@Marinski Marinski commented May 7, 2016

Thanks, works for me /May, 07, 2016/

@worldsdream

This comment has been minimized.

Copy link

@worldsdream worldsdream commented Aug 12, 2016

It was working great. Now with yoast seo premium v3.4.2, this will break the colored bulletin in top of the admin bar, can you update the code?

@mcyt

This comment has been minimized.

Copy link

@mcyt mcyt commented Aug 24, 2016

Thanks.

@mcyt

This comment has been minimized.

Copy link

@mcyt mcyt commented Aug 24, 2016

how not remove title?

@paulcollett

This comment has been minimized.

Copy link
Owner Author

@paulcollett paulcollett commented Oct 14, 2016

@worldsdream Can you link or send me a copy of yoast seo premium v3.4.2? I'll get this updated

@eric-mathison

This comment has been minimized.

Copy link

@eric-mathison eric-mathison commented Feb 18, 2017

Replace the regex with this: '/^<!--.*?[Y]oast.*?-->$/mi'

@hillicane

This comment has been minimized.

Copy link

@hillicane hillicane commented Mar 15, 2017

This worked perfect for me ... thanks!

@paulcollett

This comment has been minimized.

Copy link
Owner Author

@paulcollett paulcollett commented May 23, 2017

Thanks @eric-mathison, I've updated the gist

@worldsdream

This comment has been minimized.

Copy link

@worldsdream worldsdream commented Jun 11, 2017

Thanks, now all is working with the latest Yoast!

@Shoora

This comment has been minimized.

Copy link

@Shoora Shoora commented Aug 12, 2017

thanks!! in Yoast SEO plugin v5.2 well working

@mike-source

This comment has been minimized.

Copy link

@mike-source mike-source commented Oct 9, 2017

Not working for me:

Wordpress 4.8.2
Yoast SEO 5.5.1

@shangdev

This comment has been minimized.

Copy link

@shangdev shangdev commented Oct 17, 2017

It working,super!

@paulcollett

This comment has been minimized.

Copy link
Owner Author

@paulcollett paulcollett commented Nov 10, 2017

I've just updated the above gist. Tested with:

Wordpress 4.9
Yoast SEO 5.7.1

(/cc @mike-source)

@nucklearproject

This comment has been minimized.

Copy link

@nucklearproject nucklearproject commented Nov 13, 2017

Yoast 5.7.1
WP 4.8.3

If you activated "forced rewrite titles" don't work...
If "forced rewrite titles" is checked, the title tag it does not printt.... :/

UPDATED!
Ok, I solved it

Uncheck "forced rewrite titles"
In your header.php or your head template add this:
<title><?php wp_title(''); ?></title>

@carlitoescobar

This comment has been minimized.

Copy link

@carlitoescobar carlitoescobar commented Nov 22, 2017

Yoast SEO plugin v5.8
WP 4.9

Not working for me.

@ghub2015

This comment has been minimized.

Copy link

@ghub2015 ghub2015 commented Nov 27, 2017

It works (WP 4.9 + plugin v5.8) if you get rid of the check on 'WPSEO_VERSION' but I am not sure of any performance or reliability implications.
Specifically:

//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);
//}

Edit: I just looked through the code and the check for WPSEO_VERSION should really work, so I am a bit puzzled myself. Anyway, consider this a drive-by comment as I wasn't specifically here for this, but just stumbled upon it. But, this is truly a wake up call for me to scrutinize these WordPress plugins more thoroughly.

@paulcollett

This comment has been minimized.

Copy link
Owner Author

@paulcollett paulcollett commented Feb 16, 2018

Performance wise, it would be exactly same. I'll update the code above

@PaulRayden

This comment has been minimized.

Copy link

@PaulRayden PaulRayden commented Mar 16, 2018

Nice, thx u

@TomasHurtz

This comment has been minimized.

Copy link

@TomasHurtz TomasHurtz commented May 9, 2018

This snippet works fine but my functions file complains that the code is not valid!
yoast-snippet

@paulcollett

This comment has been minimized.

Copy link
Owner Author

@paulcollett paulcollett commented Jul 7, 2018

@TomasHurtz, should be valid PHP5+, maybe your code editor is reporting for earlier versions of PHP.

Glad to hear it's still working for the community!

@wpplayer

This comment has been minimized.

Copy link

@wpplayer wpplayer commented Sep 15, 2018

Thanks. Works great with Yoast v8.2.

@jamaluddinrumi

This comment has been minimized.

Copy link

@jamaluddinrumi jamaluddinrumi commented Sep 30, 2018

It works (WP 4.9 + plugin v5.8) if you get rid of the check on 'WPSEO_VERSION' but I am not sure of any performance or reliability implications.
Specifically:

//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);
//}

Edit: I just looked through the code and the check for WPSEO_VERSION should really work, so I am a bit puzzled myself. Anyway, consider this a drive-by comment as I wasn't specifically here for this, but just stumbled upon it. But, this is truly a wake up call for me to scrutinize these WordPress plugins more thoroughly.

+1

i use yoast 8.3 and wp 4.9

@mertsabuncu

This comment has been minimized.

Copy link

@mertsabuncu mertsabuncu commented Nov 17, 2018

I tried, and it happened. I cited my source in a paper, thank you.
https://mertsabuncu.com/wordpress-sayfa-kodlarindan-yoast-seo-yorumlarini-kaldirin/

@cormartur

This comment has been minimized.

Copy link

@cormartur cormartur commented Nov 23, 2018

@cormartur

This comment has been minimized.

Copy link

@cormartur cormartur commented Nov 23, 2018

@solucionesuno

This comment has been minimized.

Copy link

@solucionesuno solucionesuno commented Apr 30, 2019

since last update of yoast 11 there is a problem with this cause it is printing code on header

@maxyudin

This comment has been minimized.

Copy link

@maxyudin 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

This comment has been minimized.

Copy link

@DennysDionigi 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

This comment has been minimized.

Copy link

@kangmis77 kangmis77 commented Dec 10, 2019

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

@jeremypetrequin

This comment has been minimized.

Copy link

@jeremypetrequin 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

This comment has been minimized.

Copy link

@Ridys Ridys commented Feb 27, 2020

Thanks

@devendrabhandari

This comment has been minimized.

Copy link

@devendrabhandari 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

This comment has been minimized.

Copy link

@mohsinr 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

This comment has been minimized.

Copy link

@f0rtisyy2019 f0rtisyy2019 commented Jun 25, 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!

Also works for me. Thanks

@ulissse

This comment has been minimized.

Copy link

@ulissse ulissse commented Sep 6, 2020

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

@dubiolo

This comment has been minimized.

Copy link

@dubiolo dubiolo commented Nov 17, 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!

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

This comment has been minimized.

Copy link

@justinrains justinrains commented Feb 2, 2021

Awesome! Thanks for the code. Much appreciated!

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