wordpress og:image featured image

Basically, I am using facebook markup on my website.

If an article has more than one image the facebook markup doesn’t pick up the featured image for sharing, but does with only one image in the article.

Read More

I would like the facebook markup to pick up featured image no matter how many images are in the article?

Here is my markup:

<meta property="og:image" content="<?php if (function_exists('wp_get_attachment_thumb_url')) {echo wp_get_attachment_thumb_url(get_post_thumbnail_id($post->ID)); }?>" />

Does anyone know what needs changing?

Problem has been driving me nuts.

Regards

Related posts

Leave a Reply

2 comments

  1. If you are not using any SEO plugin and want to do it in code, you might put this inside your <head> tags, probably in header.php of your theme

    <?php if (has_post_thumbnail()) { ?>
    <meta property="og:image" content="<?php echo get_the_post_thumbnail_url(get_the_ID(), 'large'); ?>" />
    <?php } ?>
    

    Where large selects the resized media size, you might want to play with the dimensions or even define custom media size to match facebook’s dimension recommendations.

  2. OG images can be tricky…

    Make sure that there are no duplicate OG image tags, YOAST SEO also creates OG Image tags and some other SEO plugins might do the same.

    I have seen that this confuses Facebook.

    Just check your source code to see that the correct image is echoed in the OG tag.

    Lastly use the Facebook debugger tool to see if you pick up any problems.