Skip to content

Instantly share code, notes, and snippets.

@llgruff
Last active March 4, 2021 13:34
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save llgruff/a7ab776167aa0ed307ec445df54e5fdb to your computer and use it in GitHub Desktop.
Save llgruff/a7ab776167aa0ed307ec445df54e5fdb to your computer and use it in GitHub Desktop.
Remove [All in One SEO Pack] or [Yoast SEO] HTML Comments in WordPress (for functions.php)
<?php
/**
* Remove [All in One SEO Pack] HTML Comments
* @link //gist.github.com/llgruff/a7ab776167aa0ed307ec445df54e5fdb
*/
if (defined('AIOSEOP_VERSION')) {
add_action('get_header', function() {
ob_start(
function($o) {
return preg_replace('/\n?<.*?One SEO Pack.*?>/mi','',$o);
}
);
});
add_action('wp_head', function() {
ob_end_flush();
}, 999);
}
/**
* Remove [Yoast SEO] HTML Comments
* @link //gist.github.com/llgruff/a7ab776167aa0ed307ec445df54e5fdb
* @link //gist.github.com/paulcollett/4c81c4f6eb85334ba076
*/
if (defined('WPSEO_VERSION')) {
add_action('get_header', function() {
ob_start(
function($o) {
return preg_replace('/\n?<.*?Yoast SEO.*?>/mi','',$o);
}
);
});
add_action('wp_head', function() {
ob_end_flush();
}, 999);
}
@Blogthetech
Copy link

Work so well. Thanks buddy

@MissZougou
Copy link

Hi,
I always used this snippet, but it doesn't seem to work anymore with version 4 of AIO SEO PACK.

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