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”
// Add to your Wordpress Theme's functions.php
// Remove All Yoast HTML Comments
// https://gist.github.com/paulcollett/4c81c4f6eb85334ba076
add_action('wp_head',function() { ob_start(function($o) {
return preg_replace('/^\n?<!--.*?[Y]oast.*?-->\n?$/mi','',$o);
}); },~PHP_INT_MAX);
@Marinski

This comment has been minimized.

Copy link

commented May 7, 2016

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

@worldsdream

This comment has been minimized.

Copy link

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

commented Aug 24, 2016

Thanks.

@mcyt

This comment has been minimized.

Copy link

commented Aug 24, 2016

how not remove title?

@paulcollett

This comment has been minimized.

Copy link
Owner Author

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

commented Feb 18, 2017

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

@hillicane

This comment has been minimized.

Copy link

commented Mar 15, 2017

This worked perfect for me ... thanks!

@paulcollett

This comment has been minimized.

Copy link
Owner Author

commented May 23, 2017

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

@worldsdream

This comment has been minimized.

Copy link

commented Jun 11, 2017

Thanks, now all is working with the latest Yoast!

@Shoora

This comment has been minimized.

Copy link

commented Aug 12, 2017

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

@mike-source

This comment has been minimized.

Copy link

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

commented Oct 17, 2017

It working,super!

@paulcollett

This comment has been minimized.

Copy link
Owner Author

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

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

commented Nov 22, 2017

Yoast SEO plugin v5.8
WP 4.9

Not working for me.

@ghub2015

This comment has been minimized.

Copy link

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

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

commented Mar 16, 2018

Nice, thx u

@TomasHurtz

This comment has been minimized.

Copy link

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

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

commented Sep 15, 2018

Thanks. Works great with Yoast v8.2.

@gangsarswapurba

This comment has been minimized.

Copy link

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

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

commented Nov 23, 2018

@cormartur

This comment has been minimized.

Copy link

commented Nov 23, 2018

@solucionesuno

This comment has been minimized.

Copy link

commented Apr 30, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.