3 notes &
Tell Facebook which image to use when people share your page
This is a very nice tutorial on how to write a hook for your Drupal site to specify which image Facebook should pull in when people share your page on Facebook. (Note: We provided a more universal instruction on how to manually insert this meta tag - and a few others - a few years ago).
Update:
We’ve had to modify his code somewhat to get it to work. Here’s what we added to our template.php file (obviously change mytheme to your theme’s name, and optionally change the URL to the image you want to pull if you don’t want to pull the theme’s logo):
function mytheme_preprocess_page(&$vars){
global $base_url;
$img = $base_url.base_path().path_to_theme()."/logo.png";
if($vars['is_front'] != TRUE){
if(isset($vars['node']->field_image['und'][0]['uri'])){
$img = file_create_url($vars['node']->field_image['und'][0]['uri']);
}
}
$element = array(
'#tag' => 'link',
'#attributes' => array(
"rel" => "image_src",
"href" => $img,
),
);
drupal_add_html_head($element,'facebook_share_image');
}
