Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jakebellacera/c2aab8f786a0617b27dd4914c70463d4 to your computer and use it in GitHub Desktop.

Select an option

Save jakebellacera/c2aab8f786a0617b27dd4914c70463d4 to your computer and use it in GitHub Desktop.

Revisions

  1. jakebellacera revised this gist Apr 23, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions disable-yoast-seo-automatic-og-image-lookup.php
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@

    /**
    * 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
  2. jakebellacera created this gist Apr 23, 2020.
    26 changes: 26 additions & 0 deletions disable-yoast-seo-automatic-og-image-lookup.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?php

    /**
    * Plugin Name: Disable Yoast SEO Automatic Open Graph Images
    * 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;
    }