I am trying to remove the Yoast WordPress SEO on a certain page because it is conflicting with another plugin.
I tried adding the code below to my functions.php but it does not seem to work, any help is appreciated.
Thank You
function remove_wpseo(){
if ( is_page(944)) {
global $wpseo_front;
remove_action( 'wp_head', array($wpseo_front, 'head'), 2 );
}
}
add_action('wp_enqueue_scripts','remove_wpseo');
Just in case someone is wondering why above methods are not working after the upgrade, this is the new method of disabling Yoast SEO output as of version 14.0
add_action( 'template_redirect', 'remove_wpseo' );
function remove_wpseo() {
if ( is_page ( 944 ) ) {
$front_end = YoastSEO()->classes->get( Yoast\WP\SEO\Integrations\Front_End_Integration::class );
remove_action( 'wpseo_head', [ $front_end, 'present_head' ], -9999 );
}
}
Hope this helps!
Enqueing is not the right moment to remove an action, use template_redirect
instead:
add_action('template_redirect','remove_wpseo');
function remove_wpseo(){
if ( is_page(944)) {
global $wpseo_front;
remove_action( 'wp_head', array($wpseo_front, 'head'), 2 ); // <-- check priority
}
}
Check the priority that the plugin uses to add the wp_head
action as the removal has to be the same and none if empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With