Change so_cuws_remove_frontend_html_comments implementation
Emanuel-23 opened this issue · 4 comments
While it has been the only way to remove the yoast seo comments a long time period, it is NO longer needed to use preg_replace to remove the ugly html comments from the dom.
so the function in so_cuws_remove_frontend_html_comments
in class-so-clean-up-wp-seo.php
could be easier when just using the yoast filter. (see more details below).
Interesting fact: at least in my case with the roots/bedrock
stack and using roots/sage
(version 10), the use-combination of the plugin 'woocommercer-germanized' together with this plugin results in a white screen of death (after investigation: "headers already send" and to be more concrete, coming from the so_cuws_remove_frontend_html_comments function)...
This does not occur when disabling the option using the settings.
Expected behavior
just an easier and more concrete implementation.
Current behavior implementation
if ( ! empty( $this->options['remove_html_comments'] ) ) {
if ( defined( 'WPSEO_VERSION' ) ) {
add_action( 'get_header', function () { ob_start( function ( $o ) {
return preg_replace( '/\n?<.*?Yoast SEO plugin.*?>/mi', '', $o ); } ); } );
add_action('wp_head',function (){ ob_end_flush(); }, 999);
}
}
Possible way to add this
replace in CUWS::so_cuws_remove_frontend_html_comments Line 223 - 227 with
if ( ! empty( $this->options['remove_html_comments'] ) ) {
add_filter( 'wpseo_debug_markers', '__return_false' );
}
thats it, or actually wrap it with a condition for checking seo version and for providing backwards support.
Thanks for the suggestion to simplify this. Do you know which version this filter was added? That would be needed to make this function a conditional one :)
So the filter was added on version 14.1. I have been trying to pull out the plugin data with the get_plugin_data()
function (source), but to no avail as for some reason that only outputs the text-domain...
or actually wrap it with a condition for checking seo version and for providing backwards support.
If you have any ideas on how to implement this condition then I would like to suggest you do a PR.
Thanks!
Found it actually by using the constant WPSEO_VERSION
. New version will be released soon, thanks for the tip.
see this comment; improved the filter with suggested version_compare()
and released 3.14.7