Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakebellacera/c2aab8f786a0617b27dd4914c70463d4 to your computer and use it in GitHub Desktop.
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.
<?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