Sometimes the default Yoast SEO settings aren’t quite the way you want. For example, I wanted to enable twitter cards using the “Summary with large image” card type by default on a multisite network. Below you’ll find a snippet that does that, and can also be adapted to change any default option while still letting users override them if desired.
add_filter('wpseo_defaults', function($defaults, $option_name) {
if($option_name === 'wpseo_social') {
$defaults['twitter'] = true;
$defaults['twitter_card_type'] = 'summary_large_image';
}
return $defaults;
}, 10, 2);
Tip
Looking for the proper $option_name
? If you enable the WP_DEBUG
constant in your wp-config.php
, it’ll show up on the relevant tab in the Yoast SEO admin:
This snippet was tested with Yoast SEO 2.3.5, but is likely to work for both older and newer versions.