0

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

0

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.

  • do you mean 'normal', s'small' or 'large', can you be more specific, please. Thanks – 10Y01 Oct 8 '16 at 21:56
  • Yes, you can put the image size name, for the name it depends on your theme (or plugins). You can use get_intermediate_image_sizes to discovery them all. – Benoti Oct 9 '16 at 8:06
  • Thank You, Benoti. I've reading about and started using the 'name' for thumbnail sizes. It turns out that the problem is I'm using 'future' post_status (for an event site. And that is the problem. (meaning the post doesnt exist yet, well kinda... since WP 3.8) that explains why sometimes i got the page not found as og:title. So no og:image, nor og:anything was retrieved. – 10Y01 Oct 11 '16 at 1:17
0

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:

Marking future dated post as published

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.