Facebook OpenGraph not showing the image
-
I have this function in my functions.php file but when I try to share a post, I can not see the image. The title, the url are ok, but the image is empty <meta property=”og:image” content=””/>
function insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
echo ‘<meta property=”fb:admins” content=”636611903019820″/>’;
echo ‘<meta property=”og:title” content=”‘ . get_the_title() . ‘”/>’;
echo ‘<meta property=”og:type” content=”article”/>’;
echo ‘<meta property=”og:url” content=”‘ . get_permalink() . ‘”/>’;
echo ‘<meta property=”og:site_name” content=”raconets.com”/>’;
if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
$default_image=”https://raconets.com/logo.png”; //replace this with a default image on your server or an image in your media library
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 “
“;
}
add_action( ‘wp_head’, ‘insert_fb_in_head’, 5 );
- The topic ‘Facebook OpenGraph not showing the image’ is closed to new replies.