skip to Main Content

I am attempting to disable Yoast SEO’s Twitter Cards using the hook system. I’ve been able to disable Yoast’s Open Graph using the following method, but for some reason, the Twitter cards refuse to go away. Here’s my current code:

// Inside my Open Graph function:
global $wpseo_og; 
remove_action( 'wpseo_head', array( $wpseo_og, 'opengraph' ), 30 );

// Inside my Twitter Card function:
global $wpseo_twitter;
remove_action( 'wpseo_head', array( $wpseo_twitter, 'twitter' ), 40 );

I’ve seen this code on several forums, but for some reason, only the Open Graph removal seems to be working on my site. Any help would be greatly appreciated.

6

Answers


  1. Chosen as BEST ANSWER

    I finally found the answer by outputting all of the hooks that were being attached to the wpseo_head hook. Here's the function that worked:

    remove_action( 'wpseo_head' , array( WPSEO_Twitter , 'get_instance' ) , 40 );
    

    Hopefully someone finds this useful.


  2. Try this:

    remove_action( 'wpseo_head' , array( 'WPSEO_Twitter' , 'get_instance' ) , 40 );
    
    Login or Signup to reply.
  3. Yoast seo has the following hook in “wp-content/plugins/wordpress-seo/frontend/class-twitter.php” and it can be used to disable it :

    public function twitter() {
    
        /**
         * Filter: 'wpseo_output_twitter_card' - Allow disabling of the Twitter card
         *
         * @api bool $enabled Enabled/disabled flag
         */
        if ( false === apply_filters( 'wpseo_output_twitter_card', true ) ) {
            return;
        }
    

    So, the above hook can be used to disable it :

    add_filter('wpseo_output_twitter_card', '__return_false' );
    
    Login or Signup to reply.
  4. Yoast seo has the following hook to disable or remove Yoast SEO’s Twitter Cards and disable Yoast’s Open Graph using the following method,

    
        add_action('wp_head', 'remove_all_wpseo_og', 1);
        function remove_all_wpseo_og() {
        remove_action( 'wpseo_head', array( $GLOBALS['wpseo_og'], 'opengraph' ), 30 );
        remove_action( 'wpseo_head', array( wpseo_output_twitter_card , 'get_instance' ) , 40 );
        }
    
    
    Login or Signup to reply.
  5. Yoast update year 2020, manually turning social media tags on or off.

    As of Yoast SEO 14.0 the plugin is more like Danish Lego and building up the head meta tags as "presenters". Twitter is one of them. It seems like the idea is to add more or less blocks to the final meta output. This is handy as Yoast modules – or third part combinations – get seemless integrated into the main plugin. In the end, and in the future, there is always a combination of meta(s) for Pinterest, Twitter or next generation social media to come.

    function intervik_wpseo_frontend_presenters($presenters){
    
        /* return all WITHOUT Twitter meta output */
        
        if($matches = preg_grep('/Twitter/', $presenters)) return array_diff($presenters, $matches);
            else return $presenters;
    }
    add_filter('wpseo_frontend_presenter_classes', 'intervik_wpseo_frontend_presenters', 10, 1);
    

    Some meta still have the old filter(s) left to turn different output on or off Like add_filter('wpseo_output_twitter_card', '__return_false' ); But Facebook is part of the opengraph, shared by other social media. There is no explicit Facebook filter, only some like the FB app-id output.

    SEO 14.0 architecture is new, and all correct documentations are hard to find on search engines. AS Yoast is a very common WordPress plugin, old information with wrong approaches dominates. There might be other filters and solutions as well.

    If you manually wanna remove the Twitter meta, you propably are interested to remove other meta as well in the future, or at least have som knowledge of the new API.

    Here is a dump of common 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"
    }
    
    Login or Signup to reply.
  6. try this ! it works for me. just add this code to function.php or to your plugin:

    add_filter('wpseo_enhanced_slack_data', function($data, $presentation){return []; }, 10, 2 );

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search