How to set custom Post feature image as og:image ?
This tag is useful to give a link preview with custom post featured image, when you share the link post with social sites like- Facebook, Whatsapp, Twitter etc.
og refers to Open Graph meta tag, you have to add add following line with your image address in the header part of the page
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
This is the way to set a particular static image as an open graph meta tag, but if you want to change image dynamically or according to your post then you have to follow below mentioned code.
<meta property="og:image" content="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>" />
Comments
Post a Comment