-
-
Save trajche/9305892 to your computer and use it in GitHub Desktop.
add_action('get_header', 'start_ob'); | |
add_action('wp_head', 'end_ob', 999); | |
function start_ob() { | |
ob_start('remove_yoast'); | |
} | |
function end_ob() { | |
ob_end_flush(); | |
} | |
function remove_yoast($output) { | |
if (defined('WPSEO_VERSION')) { | |
$targets = array( | |
'<!-- This site is optimized with the Yoast WordPress SEO plugin v'.WPSEO_VERSION.' - https://yoast.com/wordpress/plugins/seo/ -->', | |
'<!-- / Yoast WordPress SEO plugin. -->', | |
'<!-- This site uses the Google Analytics by Yoast plugin v'.GAWP_VERSION.' - https://yoast.com/wordpress/plugins/google-analytics/ -->', | |
'<!-- / Google Analytics by Yoast -->' | |
); | |
$output = str_ireplace($targets, '', $output); | |
$output = trim($output); | |
$output = preg_replace('/^[ \t]*[\r\n]+/m', '', $output); | |
} | |
return $output; | |
} |
This is very helpful! Thank you. It works perfectly in a theme's function.php - however, is there any way to add this to a plugin? I've tried without luck. I appreciate any insight.
Fusse's example works Great. Thanks Fusse!
But keep in mind NO MATTER which method you use it will BREAK forced title rewrites! (At least in the version I am using, 3.4.2)
They use the "debug_marker" (The comments) to place a the forced title rewrite. If you are not using "force title rewrite" then you should be fine.... For now.
// Find all titles, strip them out and add the new one in within the debug marker, so it's easily identified whether a site uses force rewrite. $content = preg_replace( '/<title.*?\/title>/i', '', $content ); $content = str_replace( $this->debug_marker( false ), $this->debug_marker( false ) . "\n" . '<title>' . $title . '</title>', $content );
As you can see they use the opening comment tag as a point to insert the title tag.
Or...just use another plugin :)
We’ve Migrated from Yoast SEO - https://roots.io/weve-migrated-from-yoast-seo/
Hello,
How to remove this line from inspect element.
Hi all... This is how I got rid of the two html comments. Code in my functions.php: (latest WP and Yoast SEO)
Original head() function in class-frontend.php of the plugin is this: