WordPress Opengraph and Microdata Generation without a plugin

Its really useful to have Opengraph (Facebook) and Microdata (Twitter) information in your blog header.

The Facebook Opengraph and Schema.org microdata lets you optimize your blog much more better and helps search engines to index your website better to show rich snippet.

It also lets Facebook and Twitter users to share your blog with proper title, description, url and image.

There are loads of plugins available to do this, but why use a plugin when its only a few lines of code?

Add this to your header.php, perhaps just below wp_head();

</p>
&lt;meta property="og:title" content="&lt;?php bloginfo('name');?&gt;" /&gt;
&lt;meta property="og:type" content="article" /&gt;
&lt;meta property="og:url" content="&lt;?php bloginfo('url');?&gt;" /&gt;
&lt;meta property="og:image" content="-- PUT AN IMAGE HERE --" /&gt;
&lt;meta property="og:site_name" content="&lt;?php bloginfo('name');?&gt;" /&gt;
&lt;meta property="og:description" content="&lt;?php bloginfo('description');?&gt;" /&gt;
&lt;meta property="og:locale" content="en_GB" /&gt;
&lt;meta property="fb:admins" content="-- PUT YOUR FACEBOOK ID HERE --" /&gt;
&lt;meta itemprop="name" content="&lt;?php bloginfo('name');?&gt;"&gt;
&lt;meta itemprop="description" content="&lt;?php bloginfo('description');?&gt;"&gt;
&lt;meta itemprop="url" content="&lt;?php bloginfo('url');?&gt;"&gt;
<p style="text-align: justify;">

It’s almost cut n paste, but make sure you change the og:image parameter to have a nice image show when users share your content on Facebook.

Also, insert your Facebook ID  in the fb:admins parameter. Don’t know your Facebook ID? https://www.facebook.com/whatismyid

Done!

Author: Kieran Barnes

Kieran is a PHP developer with 15 years commercial experience. Specialist in WordPress, CakePHP, CubeCart and all things PHP.

One thought on “WordPress Opengraph and Microdata Generation without a plugin”

  1. Hi Keiran,

    Thanks for this solution.

    Don’t you think it is necessary to add in the header:

    xmlns:og=”http://ogp.me/ns/fb#” xmlns:fb=”http://www.facebook.com/2008/fbml”
    +
    itemscope itemtype=”http://schema.org/Blog

    Thanks,

Leave a Reply

Your email address will not be published. Required fields are marked *