Description:

Adding open graph metatags to your header it’s important because every time you add a social plugin and one of your visitors will share content, or like posts or send a url a lot of information will be attached on facebook.

In this tutorial i’ll show you how to add these meta tags with bit of code without plugins.

Apply this code to your function.php template file.

The Code:

function wpc_fb_opengraph() {
$wpc_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
?>
<meta property="og:title" content="<?php the_title(); ?>" />
<meta property="og:url" content="<?php the_permalink(); ?>" />
<meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
<meta property="og:description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); ?>" />
<meta property="fb:app_id" content="APP ID HERE">
<meta property="fb:admins" content="YOUR FB USER ID (OR USERNAME) HERE"/>
<meta property="og:image" content="<?php echo $wpc_image_url[0] ?>"/>
<?php }

add_action('wp_head', 'wpc_fb_opengraph');