21.1.11

Displaying Wordpress' custom field thumbnails on Facebook

I recently found myself redesigning the Culebrita Macheteada site, and came up with the trouble of calling up the custom field images so I could share them on Facebook. First of all, to setup an image so it can show on the Facebook Share preview you need the following code between the <head> section of your site:
<link rel="image_src" href="http://www.example.com/image.jpg" /> 

Being that the case, I had two problems:
1. The image I wanted to show on Facebook was only used for the front page, so it couldn't be linked by Facebook whenever it crawled throughout the post; and,

2. The link tag had to be used from outside the loop.

Using this great post as an initial step, I came up with this. Feel free to use it if you find it useful:

<?php if (is_single()) { ?>
 <?php
  global $wp_query;
  $postid = $wp_query->post->ID;
 ?>
 <link rel="image_src" href="[Image-folder]/<?php echo get_post_meta($postid, 'Customfield', true); ?>" />
<?php } ?>

And there you go! Images from custom fields being used as you wish on Facebook Share.

2 comentarios :

DrMartin dijo...

Falta el .sv

Snipe dijo...

No, fue en el sitio anterior al cual implementé esto; ahora ya no formo parte de él. Un saludo.