Add Facebook To Your Thesis Blog

Facebook announced a ton of new technology at their F8 Developers Conference yesterday in San Francisco. At the conference they unveiled a ton of new technologies that I think could reshape the web.


This is a “gloves off” move between Facebook and Google. Facebook is claiming they have a better way of determining the relevance of web pages, based on social interactions online rather than by ranking pages based on back links. They call it the Open Graph.

Facebook for Websites

There are a bunch of new Facebook social plugins you can add to your website. One of the things that you can do immediately is allow your visitors to “Like” any web page or blog post on your site by adding a few simple lines of code. You can literally treat URL on your website like a Facebook page!

Here’s an example of a button that shows your visitor who else in their social network “Liked” this page, and allows them to “Like” your page with a comment too.

It’s dynamic – go ahead – Click It!

Adding Facebook Social Plugins to Your Blog (or Website)

Adding one of these to your website is super easy. Just go to the Like Button plugin page at Facebook, and they have a tool that helps you get the code.

facebook-like-button-code-generator

Enter in the URL of your page and push the Get Code button and you’ll get the code you can embed on your website. You need to use the iFrame version of the code unless you’ve added the Facebook JavaScript SDK to your site.

facebook-like-button-code

What if I want to Add it to ALL my Blog Posts?

That’s cool for an individual page or post on your site, but what if you want to include this on all your blog posts?

Well, if you are using the Thesis WordPress Theme you can use “hooks” and a little WordPress code to easily add this to all your blog posts automatically.

Here’s how to do it.

Thesis conveniently provides a hook called thesis_hook_after_post that allows you to add anything you want after every post on your site. Here’s the code you need to add to that hook to get this new Facebook Like Button to show up at the bottom of every post:


/* Facebook Plugin After Post Hook */
function add_social_media () {
if (is_single()) {
?>
<?php
echo '<iframe src="http://www.facebook.com/widgets/like.php?href=';
echo trackback_url(display);
echo ' "scrolling="no" frameborder="0" style="border:none; width:450px;height:30px"></iframe>'
?>
<?php
}
}
add_action('thesis_hook_after_post', 'add_social_media');

The WordPress function trackback_url(display) gives you the URL of your blog post so that the likes are unique to the particular post instead of your whole blog.

You can add this hook to your custom_functions.php file like this, or using the Rick Beckman’s excellent OpenHook plugin.

Comments

By Don Campbell

Don is President and founder of Expand2Web.com, which provides WordPress Websites and Local Search Marketing solutions and training for small business owners and consultants.Don is a veteran of Silicon Valley Startup Interwoven, where he was created a $5M product line and Microsoft where he was technical evangelist for Office and Office Live. Check out his blog at http://www.expand2web.com/blog.

Leave a comment