WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As per documentation I satisfied all the requirements of the like button by using the meta-tags, however I still don't get the image I would like linked by Facebook: it always goes fishing for another image in the sidebar.

Now, of course I could solve this by being explicit about which image I really want but I do I get that image from Wordpress? Is there a function like post_image() that would print its URL like there is for the permalink?


share|improve this question
@L. De Leo: Can you post your current code? PHP code and the HTML it generates. Or can you point us to a live site that shows the problem? – Jan Fabry Nov 17 '10 at 12:08
I've noticed something strange: when I share something to Facebook by clicking the Like on my site it gets the wrong image. When instead I post the link in my status on Facebook the correct image is presented as the first option. – Lorenzo Nov 19 '10 at 15:24

Yoast.com actually covered this quite recently...

if (  is_singular() ) {
  global $post;
  if ( current_theme_supports('post-thumbnails') 
      && has_post_thumbnail( $post->ID ) ) {
    $thumbnail = wp_get_attachment_image_src( 
      get_post_thumbnail_id( $post->ID ), 'thumbnail', false);
    echo '<meta property="og:image" 
      content="'.$thumbnail[0].'" />';  
  echo '<meta property="og:title" 
    content="'.get_the_title().'" />';
  if ( get_the_excerpt() != '' )
    echo '<meta property="og:description" 
      content="'.strip_tags( get_the_excerpt() ).'" />';

Explanation and more details are here: http://yoast.com/facebook-share-wordpress/

share|improve this answer
Joost is the best, god bless him! ;-) – Lorenzo Nov 16 '10 at 19:29
Doesn't work for me :( i tried to create a thumbnail but nothing – Lorenzo Nov 16 '10 at 20:05
What doesn't work? I haven't played around with this very much myself yet. – Lars Koudal Nov 16 '10 at 22:52

Here's a code sample from a recent project. This sets the OpenGraph properties for a specific post. Add the code to the header.

<?php if (is_single()) { // Display only on single posts ?>
<?php $thumbnail_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID)); 
// Optionally, use the code below (untested) to get a thumbnail based on a specific thumbnail size
// $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'custom-thumbnail-name'); 
<meta property="og:title" content="<?php echo get_the_title($post->ID); ?>" />
<meta property="og:url" content="<?php echo get_permalink($post->ID); ?>" />
<meta property="og:image" content="<?php echo $thumbnail_url[0]; ?>" />
<meta property="og:site_name" content="Website Name" />
<meta property="og:type" content="article" />
<meta property="fb:admins" content="732866210" />
<?php } ?>
share|improve this answer

I've used FB OpenGraph meta tags (as Jonathan wrote) on one of my websites, and it works, but not always. Sometimes, the thumbnail still is another image on the site. Then I found the link tag that is working for me:

<link rel="image_src" href="http://www.example.com/images/image.jpg" />

I'm using both methods now (link and meta tags), and the thumbnail shown on FB is always correct!

After implement any methods, you should use this tool to check it out. If should show correct title, description and thumbnail.

This is another topic you might interested in.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.