简体   繁体   中英

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.

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

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'sdimension recommendations .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM