Sharing is Caring

Based on a discussion with Andrew today I was inspired to research exactly how Facebook pulls the thumbnail images and description it uses when you share a link in your status, like so:

As I suspected, Facebook automatically picks up the title, meta description, and up to eight images it finds on the page to choose from. For greater control however there are a few specific tags you can use. This was great for Andrew because he was trying to share a full Flash site he just finished, so there was no static imagery or text to find (I’ve given him the Joel lecture of using proper alternate content ;). For me controlling Facebook share options was important because a lot of my posts don’t have much imagery with them.

If you’re a developer, then the title and description should be self explanatory, and probably already optimized for users and search engines. You can use <meta name="title" content="Your Facebook Specific Title" /> if you want to specify something different from the page title. <meta name="description" /> works as normal.

The new one to me was for an image to be specified and it’s <link rel="image_src" href="http://yoursite.com/path/to/image.jpg" />. The only caveat seems to be that its dimensions are larger than 50×50.

I wanted this information to change on a post by post basis of course so here’s a code snippet for WordPress. It gets the post’s excerpt to use as a description and the post thumbnail (now available in WP 2.9+) as the source image, all outside of the Loop in your HTML’s head.


<?php
global $wpdb;
$query = "SELECT post_excerpt FROM wp_posts WHERE ID = " . $post->ID . " LIMIT 1";
$result = $wpdb->get_results($query, ARRAY_A);

if ($result[0]['post_excerpt']) {
$description = $result[0]['post_excerpt'];
} else {
$description = "Static description if no excerpt exists";
}

$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], 'post-thumbnail', false);
if ($thumb) {
$thumb = $thumb[0];
} else {
$thumb = "http://www.yoursite.com/path/to/static-image-if-no-thumbnail-exists.jpg";
}
?>
<meta name="description" content="<?php echo $description; ?>" />
<link rel="image_src" href="<?php echo $thumb; ?>" />

For my purposes it works great, but I don’t know how well it might interact with other SEO-type WordPress plugins. For other sharing-specific meta tags, such as audio and video, check out this article, or Facebook’s developer wiki.

And please, share away. Share

25 Random Things About Me

I’m impressed/terrified that this has sucked everyone, including myself, in.

1) You ever see that show about the girl who lived with her two dads? I forget what it was called…

2) I had a sister. If she lived I might never have been born.

3) As a teenager I was hospitalized for a month at a time, four separate times. I’m happy that doesn’t happen anymore.

4) I don’t have much baby experience. I tend to view them from a distance, behind safety glass, like exotic animals at the zoo.

5) I’m really good at what I do; it took a while to realize that.

6) My favourite word is “concise.” I learned it in 9th grade from the teacher’s only critique of one of my essays. “Very concise.” I got an A on that paper. I do more with less.

7) I enjoy adding the letter “u” to words for that comedic old time-y English effect.

8) I have a love/hate relationship with web social networking. Just deleted the old livejournal this week, myspace you’re next. facebook, we’ll see…

9) Ellipses…

10) I created my 1st personal web site 10 years ago. My online presence is a meticulously crafted creature. http://www.joelsunman.com/

11) I fear I’m using the first-person narrative style too much already.

12) I over-analyze things like that, or everything. It sounds cliché in list form, but really I do. It might make me impossible to be treated with psychotherapy, but I went for 6 years.

13) The first time I danced carefree in public was at The Loop in Windsor. The song was Money City Maniacs.

14) Smooth jazz always reminds me of childhood.

15) My family are born travelers. They passed it on to me. I’ve taken some amazing trips. Hawaii, twice. I never get tired of saying that.

16) The other astronomy students hated me, I destroyed the curve. Staring into the night sky, far from light pollution and in the middle of nowhere, that’s heaven.

17) When I take my glasses off I get phantom pain sensations as if I lost a limb… on my face. It’s weird.

18) I was a nerd before being a nerd was cool. I should be getting royalty checks.

19) I make sketch comedy with my friends. And people actually watch it, people we don’t even know. Technology is amazing. http://www.thesepeoplecomedy.com/

20) Ask me about ball therapy. I won’t tell you, but you can ask.

21) The insect pictures in Zoobooks were so clear and detailed I was afraid to touch them just to turn the page.

22) I shiver like a chihuahua.

23) Is it too early to start my memoirs? They’ll be called “Running on Empty.” No, I’m not familiar with the Jackson Browne song.

24) I’m still not convinced that those WEREN’T pterodactyls flying past the window, but I was 6, so who knows.

25) I won’t hesitate to do it on my own, but I’d love the company if you’re up for it.