Last active
October 20, 2020 19:27
-
-
Save jakebellacera/c2aab8f786a0617b27dd4914c70463d4 to your computer and use it in GitHub Desktop.
Force Yoast SEO to show the default open graph image in case a feature image isn't set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Disable Yoast SEO Automatic Open Graph Images | |
* Plugin URI: https://gist.github.com/jakebellacera/c2aab8f786a0617b27dd4914c70463d4 | |
* Description: Shows the default open graph image in case a feature image isn't set, rather than showing a random image on the page. | |
* Version: 0.0.0 | |
* Author: Jake Bellacera | |
* Author URI: https://www.jakebellacera.com/ | |
*/ | |
/** | |
* Force default open graph images in case feature image isn't set | |
*/ | |
add_filter('wpseo_add_opengraph_images', 'jb_force_default_open_graph_image', 10, 1); | |
function jb_force_default_open_graph_image($images) { | |
if (!has_post_thumbnail() && WPSEO_Options) { | |
$default_id = WPSEO_Options::get('og_default_image_id', ''); | |
if ($default_id) { | |
$images->add_image_by_id($default_id); | |
} | |
} | |
return $images; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment