Skip to content

Instantly share code, notes, and snippets.

@haroldparis
Last active December 19, 2018 11:09
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 haroldparis/8a9728fa61a54600ad6b13b084677b22 to your computer and use it in GitHub Desktop.
Save haroldparis/8a9728fa61a54600ad6b13b084677b22 to your computer and use it in GitHub Desktop.
Force Yoast SEO to only use Featured Image for og:image on singular
<?php
// Tell WordPress SEO to use only full featured image for og:image output... and nothing else on singular
function only_full_og_featured_image() {
global $post;
if ( is_singular() ) {
if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( $post->ID ) ) {
$featured_image_url = wp_get_attachment_image_src(get_post_thumbnail_ID( $post->ID ), 'full' );
return $featured_image_url[0];
}
}
}
add_filter('wpseo_opengraph_image','only_full_og_featured_image');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment