Add FaceBook “Like” Button to Each Post

This document is deprecated! The information on this page refers to a Thesis version that is now obsolete. Please visit the Thesis Docs for current documentation.

Facebook is arguably the most influential social network in terms of driving traffic and prospects to your web site. Inarguably, Facebook is the most “Liked” of the social networks, with 750 million active users and counting, over half of whom login daily and average some 130 friends each.

Better get on that wagon!

You’re probably on it already. If you have a Facebook account, you may have “Liked” various articles or posts here and there. And even if you don’t have a Facebook account, you can still benefit from the Like button on your site.

Clearly, you want your friends and site visitors to “Like” your content. As a ranking signal to search engines like Google, as “social proof” that your site is worth paying attention to, and more, the importance of Facebook’s Like is impossible to ignore as a smart site owner.

Providing an easy method for your visitors to click a Facebook Like button is the cornerstone to getting started in the Like business.

Adding a Facebook Like button to each of your posts is drop-dead simple in Thesis, and does not require a plugin — the code is down below, for those in a rush to be Liked right now.

While numerous plugins do exist, some of which combine more than one social media network’s version of “Like” (e.g. plus, follow, share) buttons, the maintenance, simplicity, and low resource consumption of a custom function (PHP) make this a user-preferred method for adding Like buttons in Thesis.

But What Does the Facebook Like… Look… Like?

The code shown on this page will appear generally similar in all scenarios, but there are minor differences based on the visitor login status and whether or not a given post has had a Like yet or not.

The first set of images shows a new post with no Facebook Likes so far. The top image represents the visitor view when they, the visitor, are not logged into Facebook. The second image is what will be seen when the visitor is logged into Facebook.

Facebook Like Button - 0 Likes - Logged Out

Facebook Like Button - 0 Likes - Logged In

Note that the Like button has certain variables such as “light” or “dark” — all the images displayed here were generated using the Like code from this entry, which is the “light” version of the Facebook Like button.

Once your post gets its first “Like” from a friend or fan, the Like button changes slightly, demonstrating the number of Likes the post has received. Here is the same visitor view as before, where the post has now achieved a fair number of “Likes” — the first image is a visitor “logged out” of Facebook, and the second image shows the FB Like area from the “logged in” perspective.

Facebook Like Button - Many Likes - Logged Out

Facebook Like Button - Many Likes - Logged In

That’s the sum of the Like button. It’s there, it’s visible, and it’s begging for a click.

To get the above rolling on your Thesis site, simply add this snippet of code to your custom_functions.php file contents:

function fb_like() {
	if (is_single()) { ?>
		<iframe src="<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;"></iframe>

		<?php }

This code places a Facebook Like button at the bottom of each and every “single post” you have on your Thesis website.

It doesn’t get much easier than that — and don’t forget DIYThemes is on Facebook, too.

After all, we like to be Liked, just like you!