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
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:
Hopefully someone finds this useful.
Try this:
Yoast seo has the following hook in “wp-content/plugins/wordpress-seo/frontend/class-twitter.php” and it can be used to disable it :
So, the above hook can be used to disable it :
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,
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.
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:
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 );