Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Yoast WordPress SEO on a page

Tags:

wordpress

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');
like image 880
Peter G Avatar asked Feb 12 '23 16:02

Peter G


2 Answers

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!

like image 158
jhashane Avatar answered Feb 15 '23 06:02

jhashane


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.

like image 42
brasofilo Avatar answered Feb 15 '23 06:02

brasofilo