On shared posts, image is not featured image
-
Hello,
I added the following in my functions.php file, but the image used when sharing my posts to social media is still not the featured image.
function insert_image_src_rel_in_head() {
global $post;
if ( !is_singular())
return;
if(!has_post_thumbnail( $post‐>ID )) {
$default_image=”https://www.cheekycelie.com/wp-content/uploads/2016/06/FlowersCROPPED-e1469030701858.jpg”;
echo ‘<meta property=”og:image” content=”‘ .
$default_image . ‘”/>’;
}
else{
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post‐>ID ), ‘medium’ );
echo ‘<meta property=”og:image” content=”‘ . esc_attr( $thumbnail_src[0] ) . ‘”/>’;
}
echo “
“;
}
- The topic ‘On shared posts, image is not featured image’ is closed to new replies.