Add Facebook Open Graph Meta Data in WordPress

Facebook Open Graph Meta Data Now, normally, Facebook is really wise in pulling in the correct data for their posts after they are shared on Facebook. But recently we have been hearing reports that Facebook does not pull the correct thumbnail image once someone clicks like, not pulling the right page title, etc.

Also Check : A-Z For Setup Facebook Instant Articles for WordPress (Guide To Know)

Well, during this article, we will share however, you will add facebook open meta graphic information on WordPress themes that can solve all those problems.

3 way to add data Meta Open Chart Meta on Facebook

Add Facebook Open Graph Meta Data in WordPress

Add Facebook Open Graph Meta Data in WordPress

We have 3 ways for you, two of them need you to install an add-on. The third method is for intermediate level users who do not keep changing their themes.

Add Facebook Open Graph Meta Data with WordPress SEO

All of our websites use WordPress SEO. It not only helps you add titles and meta descriptions. It is the complete website optimization package for WordPress. WordPress SEO additionally comes equipped with social features along with the ability to add Facebook Open Graph metadata in WordPress themes.

The first thing you would like to do is install and activate the WordPress SEO plugin by Yoast. Once activated, you have to go to SEO »Social and simply check the box next to Add Open Graph Graphics Goal.

Add Facebook Open Graph Meta Data with WordPress SEO

Add Facebook Open Graph Meta Data with WordPress SEO

You can save the settings or continue and set up alternative Facebook social options on the screen. You will connect your website to your Facebook user account as the admin.

By doing this you will see Facebook ideas for this website. In addition, it will give the URL of your Facebook page and it will be added to Facebook Open chart goal.

On the same page, you will add an image and description for your cover page. Additionally, it will add a default image to be used once an item has no image associated with that.
That’s it, you have successfully added Facebook open meta data data in your WordPress theme.

Adding open chart meta data in WordPress using the official Facebook plugin

If you are using another SEO plugin like ALL in One SEO, or you just do not want to install WordPress SEO plugin, then you will continue to add Facebook meta graphics open chart with the official Facebook add-on for WordPress.

The first thing you want to do is install and activate the Facebook plugin. Simply activate the Facebook plugin you can add open meta graphic deta in the header of your topic. That’s all you have enabled Facebook open graphic meta data on your WordPress website.

Using the official Facebook plugin allows you to use several alternative features offered by this robust plugin. For example, you will use it to add a Facebook Likebox / Fanbox, embed Facebook messages, add a button for authors and much more.

Manually add Facebook Open Chart Goal data into your WordPress theme

This technique needs you to edit the theme files, so make sure you only backup the theme files before making any changes. Simply copy and paste this code into the functions.php file of your theme or into a site-specific plugin.

//Adding the Open Graph in the Language Attributes
function add_opengraph_doctype( $output ) {
return $output . ‘ xmlns:og=”http://opengraphprotocol.org/schema/” xmlns:fb=”http://www.facebook.com/2008/fbml”‘;
}
add_filter(‘language_attributes’, ‘add_opengraph_doctype’);
//Lets add Open Graph Meta Info
function insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
echo ‘<meta property=”fb:admins” content=”YOUR USER ID”/>’;
echo ‘<meta property=”og:title” content=”‘ . get_the_title() . ‘”/>’;
echo ‘<meta property=”og:type” content=”article”/>’;
echo ‘<meta property=”og:url” content=”‘ . get_permalink() . ‘”/>’;
echo ‘<meta property=”og:site_name” content=”Your Site NAME Goes HERE”/>’;
if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
$default_image=”http://example.com/image.jpg”; //replace this with a default image on your server or an image in your media library
echo ‘<meta property=”og:image” content=”‘ . $default_image . ‘”/>’;
}
else{
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘medium’ );
echo ‘<meta property=”og:image” content=”‘ . esc_attr( $thumbnail_src[0] ) . ‘”/>’;
}
echo ”
“;
}
add_action( ‘wp_head’, ‘insert_fb_in_head’, 5 );

Note: Please note to change the name of the site wherever it says “Your website name goes here”. Change the default image URL together with the image of yours. We can recommend putting a picture with your logo there, therefore, if your message does not have a thumbnail, then strip the logo of your site.

Studies show that shared messages, although not a miniature, are less effective than those with thumbnails. Do not forget to add your USER ID. You will find your Facebook user ID at this address: http://graph.facebook.com/top10best.me(Just replace top10best.me with your own username).

That’s all you want to do. As soon as you save your functions.php file (or site specific plugin), you will begin to display the Facebook meta data in the WordPress header.

We hope this article helped you to add Facebook meta data to Open Chart in WordPress. It is a good way to get users to participate along with their content on the great social platform of Facebook.

LEAVE A REPLY

Please enter your comment!
Please enter your name here