How to Add Facebook Open Graph Meta Data for Facebook share in WordPress

<?php if (is_single()) {
if (has_post_thumbnail($post->ID)) {
$thumbid = get_post_thumbnail_id($post->ID);
$postimg = wp_get_attachment_image_src($thumbid, array(500, 500));
$postimg = $postimg[0];
} else {
//$postimg = get_bloginfo('template_url') . "/images/d_facebook.png";
$og_url = get_permalink($post); ?>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>"/>
<meta property="og:title" content="
<?php the_title(); ?>"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="<?php echo $og_url; ?>"/> <meta property="og:description" content="<?php echo htmlspecialchars(get_the_excerpt()); ?>"/>
<meta property="og:image" content="<?php echo $postimg; ?>"> <?php }?>


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s