Making your Drupal page Facebook "Share a link" friendly

Making your Drupal page Facebook "Share a link" friendly
 

How to tell Facebook which image and what description to use for the preview when people post your page as a link on their profile

I was about to post a link to my latest portfolio entry on my Facebook wall and I realized it didn't pull in the correct image. I did a quick bit of research and found a solution that took only a few minutes to implement and allows you to spoon-feed Facebook a title, description and image for your page.

The "Basic Tags" section on this page gives you the three lines of code you need:

<meta name="title" content="Smith hails 'unique' Wable legacy" />
<meta name="description" content="John Smith claims beautiful football is the main legacy of Akhil Wable's decade at the club. " />
<link rel="image_src" href="http://www.onjd.com/design05/images/PH2/WableAFC205.jpg" />

In my case, I already had a Drupal CCK field containing the image path I wanted to use, as well as a page title and a short description, so all I had to do was add the lines above in the <head> seciton of the page and replace the content with the PHP variables containing the appropriate field information.

Facebook will try to guess which images to include if you don't do this, so you may find it unnecessary if it's guessing correctly. On my site, the images Facebook guessed on a number of pages were the RSS, Twitter, and Facebook icons -- completely unrelated to the content. If you're having similar issues or if you're just a control freak, the code above should help you out.

 

Comments

Pingback

[...] Making your Drupal page Facebook "Share a link" friendly | laryn.kragtbakker.com laryn.kragtbakker.com/blog/drupal-facebook-link-preview – view page – cached * Pete Rollins "Rapture" tract in the style of Jack T. Chick * This is a grain of salt * Clutching Dust and Stars (novel) — From the page [...]

Module

Hi There,Has there been a module written to do this? The obvious place for it would be in the Meta Tags Module (aka Nodewords) but it doesn't seem to allow specification of an image at this stage. 

Nice idea

That would be nice, but I haven't heard that it's been added to a module at this point. Might be a nice feature to suggest to them and I agree, nodewords might make sense.

Thanks so much for share this

Thanks so much for share this value information with us, i never think this could be so easy to fix, seems you have a lot of practice. 

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.