Remove Yoast WordPress SEO on a page

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.

Read More

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');

Related posts

Leave a Reply

4 comments

  1. 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( YoastWPSEOIntegrationsFront_End_Integration::class );
    
            remove_action( 'wpseo_head', [ $front_end, 'present_head' ], -9999 );
        }
    }
    

    Hope this helps!

  2. 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.

  3. Just in case someone still needs this. This worked for me. Change ‘page’ to ‘post’ if it’s a blog post. Instead of trying to throw out Yoast completely, just hide the meta box.

    add_action( 'add_meta_boxes', 'remove_post_meta_boxes', 11 );
    
    function remove_post_meta_boxes() {
        if( isset( $_GET['post'] ) && $_GET['post'] == '22' ) {
            remove_meta_box( 'wpseo_meta', 'page', 'normal' );
        }
    }
    
  4. @jhashane answer is correct as a straight forward answer to the question as it is. However, this removes the <tite> tag as well, and other default worpdress meta, as long as Yoast is active and installed. It just kills the output handled by Yoast.

    Disable Yoast components might be a better approach most of the time. Conflicts are often about Yoast taking over some meta, specially types or social open graphs.

    We spend hours to understand the new 14.0 version. As of Yoast SEO 14.0 the plugin is more like Danish Lego and building up the head meta tags as “presenters”.

    EX: Remove all social media components output on page id 123:

    function intervik_wpseo_frontend_presenters($presenters){
    
        /* set your conditional(s) */
        if(!is_singular(123)) return $presenters;
    
        /* return all WITHOUT Open_Graph and Twitter presenters on $page_id = 123 */
        
        if($matches = preg_grep('/Open_Graph|Twitter/', $presenters)) return array_diff($presenters, $matches);
            else return $presenters;
    
    }
    add_filter('wpseo_frontend_presenter_classes', 'intervik_wpseo_frontend_presenters', 10, 1);
    

    The filter in this example is very late. You can still use individual meta or schema etc etc filters to filter the content configuration and settings. And when you partial manually wanna disable your configuration, on page basis or so, remove “blocks” of Yoast do in your source code:

    function intervik_wpseo_frontend_presenters($presenters){
    
        /* REMOVE ONE exactly presenters (example: Canonical) */
        if(($key = array_search('YoastWPSEOPresentersCanonical_Presenter', $presenters)) !== false){
            unset($presenters[$key]);
        }
        return $presenters;
    }
    add_filter('wpseo_frontend_presenter_classes', 'intervik_wpseo_frontend_presenters', 10, 1);
    

    Remove everything except document title and description on pages:

    function intervik_wpseo_frontend_presenters($presenters){
    
        $keep[] = 'YoastWPSEOPresentersTitle_Presenter';
        $keep[] = 'YoastWPSEOPresentersMeta_Description_Presenter';
        $keep[] = 'YoastWPSEOPresentersRobots_Presenter';
        
        /* remove ALL, except title, description and robots on PAGES */
        if(is_page()) return $keep;
            else return $presenters;
    }
    add_filter('wpseo_frontend_presenter_classes', 'intervik_wpseo_frontend_presenters', 10, 1);
    

    In this case, you should use the wpseo_title etc etc filters to enable och disable Yoast content, and use WordPress default content on certain selected post or pages.

    Some meta still have the old filter(s) left to turn different “grouped” output on or off Like add_filter('wpseo_output_twitter_card', '__return_false' ); But Facebook for example, is part of the opengraph, shared by other social media. There is no explicit Facebook opengraph filter. And in the future, we will have more social media and other tags shared components.

    Lets play with bricks and blocks instead.

    Common default presenters: (dump of $presenters)

    array(27) {
      [0]=>
      string(39) "YoastWPSEOPresentersTitle_Presenter"
      [1]=>
      string(50) "YoastWPSEOPresentersMeta_Description_Presenter"
      [2]=>
      string(40) "YoastWPSEOPresentersRobots_Presenter"
      [3]=>
      string(43) "YoastWPSEOPresentersGooglebot_Presenter"
      [4]=>
      string(41) "YoastWPSEOPresentersBingbot_Presenter"
      [5]=>
      string(43) "YoastWPSEOPresentersCanonical_Presenter"
      [6]=>
      string(42) "YoastWPSEOPresentersRel_Prev_Presenter"
      [7]=>
      string(42) "YoastWPSEOPresentersRel_Next_Presenter"
      [8]=>
      string(51) "YoastWPSEOPresentersOpen_GraphLocale_Presenter"
      [9]=>
      string(49) "YoastWPSEOPresentersOpen_GraphType_Presenter"
      [10]=>
      string(50) "YoastWPSEOPresentersOpen_GraphTitle_Presenter"
      [11]=>
      string(56) "YoastWPSEOPresentersOpen_GraphDescription_Presenter"
      [12]=>
      string(48) "YoastWPSEOPresentersOpen_GraphUrl_Presenter"
      [13]=>
      string(54) "YoastWPSEOPresentersOpen_GraphSite_Name_Presenter"
      [14]=>
      string(62) "YoastWPSEOPresentersOpen_GraphArticle_Publisher_Presenter"
      [15]=>
      string(59) "YoastWPSEOPresentersOpen_GraphArticle_Author_Presenter"
      [16]=>
      string(67) "YoastWPSEOPresentersOpen_GraphArticle_Published_Time_Presenter"
      [17]=>
      string(66) "YoastWPSEOPresentersOpen_GraphArticle_Modified_Time_Presenter"
      [18]=>
      string(50) "YoastWPSEOPresentersOpen_GraphImage_Presenter"
      [19]=>
      string(54) "YoastWPSEOPresentersOpen_GraphFB_App_ID_Presenter"
      [20]=>
      string(46) "YoastWPSEOPresentersTwitterCard_Presenter"
      [21]=>
      string(47) "YoastWPSEOPresentersTwitterTitle_Presenter"
      [22]=>
      string(53) "YoastWPSEOPresentersTwitterDescription_Presenter"
      [23]=>
      string(47) "YoastWPSEOPresentersTwitterImage_Presenter"
      [24]=>
      string(49) "YoastWPSEOPresentersTwitterCreator_Presenter"
      [25]=>
      string(46) "YoastWPSEOPresentersTwitterSite_Presenter"
      [26]=>
      string(40) "YoastWPSEOPresentersSchema_Presenter"
    }
    

    Finally, here is an example of “conflicts with other plugin”. We needed to remove open graphs when plugin “Groups” restricted a page. We don wanna share or give meta for sharing here. Either, Yoast should not add this page to the sitemap, and the robots must be set as noindex. All this is decided by a custom meta on the page we talking about:

    /* Disable YOAST components output on selected pages by custom meta */
    function intervik_wpseo_frontend_presenters($presenters){
        
        if(is_singular()){
            global $post;
            $meta = get_post_meta($post->ID, 'example_custom_field', true);
            if($meta){
                add_filter('wpseo_json_ld_output', '__return_false');
                add_filter('wpseo_robots', function(){
                    return 'noindex,nofollow';
                }, 30, 1);
                if($matches = preg_grep('/Open_Graph|Twitter/', $presenters)) $presenters = array_diff($presenters, $matches);
            }
        }
        return $presenters;
    }
    add_filter('wpseo_frontend_presenter_classes', 'intervik_wpseo_frontend_presenters', 10, 1);
    

    Sitemap case: We still need a separate filter process for the sitemap as it might be loaded by ajax or cron/ not rendered as head output:

    /* -------------------- */
    // DISABLE SITEMAP EXAMPLE
    
    function intervik_wpseo_sitemap_entry_exclude($url, $type, $object){
        /* Types can be = 'term', 'post', 'user' */
        if($type == 'post'){
            $meta = get_post_meta($object->ID, 'example_custom_field', true);
            if($meta) return false;
        }
        return $url;
    }
    add_filter('wpseo_sitemap_entry', 'intervik_wpseo_sitemap_entry_exclude', 30, 3);
    

    This example above shows how the filters and presenters works
    together
    to control the output of Yoast. Adding modules like
    YOAST woocommerce or YAOST Local gives you more presenters to play with/ add or remove. And the best part of 14 API, you can
    provide your own presenter
    .

    Please comment to add another approach or trix.