metinsaylan // rogue developer

Display correct thumbnail on facebook share

//

Facebook share allows you to define certain portions of page preview. You can define them using the following tags:


[html]<!– Start of Facebook Meta Tags by shailan (http://metinsaylan.com) –> <meta property="og:title" content="Introducing dropdown menu effects" /> <meta property="og:type" content="article" /> <meta property="og:url" content="http://metinsaylan.com/introducing-dropdown-menu-effects/" /> <meta property="og:image" content="https://s3.eu-central-1.amazonaws.com/ms.static/2011/01/wp-dropdown-menu-effects-thumbnail.jpg" /> <meta property="og:site_name" content="shailan.com"/> <meta property="og:description" content="With the 1.6 update finally added jQuery effects to the dropdown menu widget. This version also brought many other features like, auto-recognizing dropdown.css in theme folder, specifiying an external theme URL, options for removing link…" /> <!– End of Facebook Meta Tags –>[/html]

Here i will show you how to implement a post thumbnail meta in order to show the right image in the post preview.

Those tags go to header.php which defines your page’s styles and meta informations.

  1. Open the `header.php`
  2. Paste the following code before `<?php wp_head(); ?>` [php title="header.php"]<?php global $wp_query; $thePostID = $wp_query->post->ID; if( has_post_thumbnail( $thePostID )){ $thumb_id = get_post_thumbnail_id( $thePostID ); $image = wp_get_attachment_image_src( $thumb_id ); echo '<meta property="og:image" content="'.$image[0].'" />'; } ?> ```
  3. Save and upload the file to your theme directory. Voila!

You can also use my Facebook Meta Tags for Wordpress plugin. It automatically inserts related tags to your site. Don’t forget to put a facebook share button to your site. You can get one here.

Cheers!

Search Display correct thumbnail on facebook share on Google