Open graph 'image' content appears empty on debugger and filled in web source
-
08-01-2021 - |
Question
Defining Open Graph meta tags like this for images.
global $post;
$postImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 1200, 9999 ), false );
<meta property="og:image" content="<?php echo $postImg[0]; ?>"/>
<meta property="og:image:width" content="<?php echo $postImg[1]; ?>"/>
<meta property="og:image:height" content="<?php echo $postImg[2]; ?>"/>
I get this in my website source:
<meta property="og:image" content="http://elpace.co/event-image.jpg"/>
<meta property="og:image:width" content="2953"/>
<meta property="og:image:height" content="4134"/>
But this in facebook's Open Graph debugger (what scrapper sees).
<meta property="og:image" content="">
<meta property="og:image:width" content="">
<meta property="og:image:height" content="">
Thank You
Solution 2
The problem was using scheduled pots with $post->post_status => 'future'. Scheduled posts can be tricky to handle.
So, the solution is to trick them into being $post->post_status => 'publish' when saved, as shown in this answer:
OTHER TIPS
wp_get_attachment_image_url
is not returning the good image size. The function need the name of the image size or a valid image size (1200 x 9999 is not a valid size, just the the way to tell add_image_size cropping definition).
Then the scrapper will be able to scrappe your content. If think there is a minimum and maximum size, and your size seems to be a little bit heavy. Hope it helps you.