Integrate Facebook’s “Like” Plugin into WordPress

Facebook recently announced the take-over of the internet with the introduction of the yet infamous “like”-button. Nevertheless, here is how you can add your own dynamic like-button for WordPress.

If you use Facebook’s generator here, you’ll get some content very similar to mine:

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fcordobo.com%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:500px; height:60px"></iframe>

Note: I highlighted the parts I replace in the next step

This would be fine, if you had only one page on your website, as the plugin only shows the url you have entered in the generator – no dynamic pages. So here’s how you can add some dynamic flavour to your new button:

Replace the following code

[…]like.php?href=http%3A%2F%2Fcordobo.com%2F

with

[…]like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>

insert it into your theme’s single.php and upload it to your server.

The final code, ready for copy & paste

This is the final code you can use in your own WordPress installation without further modifications (except the width and height). Insert it into your single.php and upload the modified file to your server.

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;show-faces=true&amp;width=500&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:500px; height:60px"></iframe>

Note: I highlighted the parts I replaced

In case you use some caching plugin, clear the cache and see the magic as it happens.

If you like it, click on “like” ;-)

73 Replies to “Integrate Facebook’s “Like” Plugin into WordPress”

  1. Hi, Im new working with all this stuff and Im really struggling to get this working. I’d really much appreciate some help!
    In my case, Im copying and pasting the “final code” you suggest on the post i want to enter next. However, when I see the blog, it only appears an URL but not the FBlike button. I guess this is because I dont know what “single.php” is and therefore Im just directly copying and paying the link on the text of the post.

    Sorry for my ignorance.

    Thanks a million in advance.

    1. You need to add the code to the file single.php in your themes folder. On Windows you can use an editor like pspad or notepad++ and insert the code.

  2. Ich habe den Code mit dem “Better Feed” Plugin in meinem RSS-Feed untergebracht.

    Wer den RSS-Feed direkt liest, der kann dann auch dort klicken. :-)

Comments are closed.