Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Add Facebook Like Button in WordPress

Do you want to add a Facebook Like button in WordPress? Facebook is the largest social media platform in the world. Using Facebook Like button, you can allow users to Like and share your content on Facebook. In this article, we will show you how to add the Facebook Like button in WordPress.

Facebook Like Button for WordPress

Method 1: Manually Add Facebook Like Button in WordPress

This method requires you to add the code directly in WordPress. If haven’t done it before, then please take a look at our beginner’s guide to pasting snippets from the web into WordPress.

First, you need to visit the Like button page on Facebook developers website and scroll down to ‘Like Button Configurator’ section.

Like button settings

Use the configuration to choose the Like button layout and size. You will see a preview of the Like button below.

You can leave the URL field empty, as we will dynamically fill in the URL in WordPress.

Once you are satisfied with the preview, click on the ‘Get Code’ button.

This will bring up a popup showing you two pieces of code snippets under the JavaScript SDK tab.

Facebook Like button code generator

Copy the first code snippet and add it to your WordPress theme’s header.php file right after the <body> tag.

Next, you need to copy the second piece of code and paste it in your WordPress theme’s template files where you want to actually display the Like button.

Most probably you will want to add it to single.php, archive.php, page.php, etc. However, if your WordPress theme uses content templates, then you will need to add it to content templates.

Please note that if you directly add these code snippets to your WordPress theme, then they will be overwritten when you update the theme.

You can avoid this, by creating a child theme and then adding these code snippets into your child theme templates.

Method 2: Add Facebook Like Button in WordPress Using a Plugin

In this method, we will be using a WordPress plugin to add Facebook Like button. This method is much easier and is recommended for beginners.

First thing you need to do is install and activate the WP Like Button plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, the plugin will add a new menu item labeled WP Like Button to your WordPress admin bar. Clicking on it will take you to plugin’s settings page.

WP Like Button settings

First you need to select where you want to display the Like button and choose whether you want the button to be mobile responsive or not.

Next, you need to provide a Facebook App ID or an Admin ID of a user who has access to Facebook insights. You can use your own Facebook username or ID here.

Under the default image setting, you can upload an image that will be used when a post or page does not have a Facebook thumbnail. Leave this option, we will show you how to set Facebook thumbnail later in this article.

Under ‘What to like’ option, you need to select ‘Each page/post will have its own like button’. After that you need to select a layout, alignment, language, for your Facebook button.

At the bottom of the page, you will be able to see a preview of how the button will appear on your site.

Once you are finished, click on the ‘Save Settings’ button to store your changes.

That’s all, you can now visit your WordPress site and you will see the Like button for each post.

Like button in WordPress

What is Open Graph Meta Data? How to Add it in WordPress

Open Graph meta data helps Facebook collect meta information about a page or post on your WordPress site. This data includes a thumbnail image, post/page title, description and author.

Facebook is quite smart in pulling up the title and description fields. However, if your post has more than one image, then sometimes it shows incorrect thumbnail when your article is shared.

If you are already using Yoast SEO plugin, then this can be easily fixed by visiting SEO » Social page and clicking on the Facebook tab.

Facebook Open Graph

For more details and alternate ways to add open graph meta data, see our guide on how to add Facebook Open Graph meta data in WordPress.

That’s all, we hope this article helped you learn how to add Facebook Like button in WordPress. You may also want to see our list of 10 best Facebook tips and tutorials for WordPress users.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

176 CommentsLeave a Reply

  1. @artist74 There is no EXACT point because it varies. The exact point is determined by where you want the code to show (for example before post / after the post / within the post etc). Once you decide that then you can also do further styling via CSS!

  2. any words of advice about the XFBML version? I copied the code straight from the facebook developer page, need to know if there is anything to do?

  3. I have a wordpress.com. I have no idea where to start with adding the Facebook Like button. I have been trying to find the single.pnp option. I just need a start on where to find it as I tried the Appearance and then go to theme and then what?Please can you advise?

  4. I’m torn between adding the facebook like button at the top of my posts or near the bottom, so I added it in both places. Does anyone know if this can cause issues to have 2 like buttons on one post?

  5. Hi, I placed the code in the single.php file and inside the loop as you have instructed. When I Like the post everything works correctly except from the title of the post on FB’s wall.

    For example on MyWebiste.com I like the post with a title MyPost.

    On FB wall shows that someone “likes MyWebiste on MyWebiste.com”, not “MyPost on MyWebiste.com”

    However, the link of “MyWebsite” links correctly to the respective article, “MyPost”.

    For me that means that the code works just fine and retrieves the right article, but not the title of the article and I’m trying to figure out if I need to do something else in order to show the title of the posts on FB wall and not only their right links.

    Any suggestions would be appreciated.
    Thank you.

    • That’s weird because it should take your page title. But to override an fix this issue, look at the resource link that we have in this article. You will need to add og:title meta tag.

      Admin

  6. Hello..
    I’m a site owner and I want to know who’s clicked the like button on each post. Not just the number of people. Is that possible?

  7. Thanks for the guide! I successfully added the ‘like’ button to my individual pages but I’m still having problems adding it to my main site which aggregates all the posts. Do you know which page I’m supposed to add it to and where?

    Thanks again,
    Aaron

  8. Hy!

    My problem is that if I “Like” a post on my site (which is named kukkold.hu) the facebook shows on my profile page that I like the kukkold.hu link on the site kukkold.hu. I experience this at every post, so I always like the main page of my site instead of the link and name of the post. What can be the problem? I tried varius like plugins, and I have inserted the code directly into the loop, but the problem is always the same and it’s really annoying. For a test I wrote a specific permalink into the space of the ID)); ?> block, but the problem was the same again.
    The like counter goes well, so it knows which post how many times was liked.
    What should I do? Please help me!

    Thank you!

  9. im using wordpress.com and i trying to add the facebook like box in my blog but i doesn’t work. i read some forum that saying wordpress.com cant read iframe code. is that true? any solution?

  10. I added the code in the loop as you sayed…but nothing happens!! I tried more and more times, in different parts of the loop…. it just doesn’t work!! Any suggestion? Thanks

  11. This is great, however I am encountering a glitch. The code functions fine and everything, but when I like it, instead of ‘liking’ the specific post, it instead ‘likes’ the parent home page. The same shows up on the Facebook feed, just the home page. Have you encountered this problem, and what can I do to fix?

    Thanks!

  12. Thanks so much for this.

    I was wondering – are you using this iframe (in the single.php) w/ meta tags in header.php?

    I’m wondering if the URL in the facebook meta tags is conflicting with my ability to use the edited like button you have here?

    Thanks so much,

    Wil

  13. Thanks for this great resource! I had played around with some plugins but they just weren’t working well for me, then I found your tutorial and just edited the code and VOILA! Success!

    Thanks!

  14. Hi!

    Thanks for this code, but something not working well…
    For example, if I go on post, I see “Like button and Be the first…message” Ok. Fine! No one like ’till now, doesn’t matter, I will be the first.. so click, Like! And then! Wow! I see that 178 people acctualy like this, but I couldn’t see that untill I like it first. Do you understand? My english is not so good, but hope you can understand what I am talking about…

    If you find a time to go on my page, and then on any single post, you will see Like button and message Be the first… but if you like it, than you’ll find out, that you weren’t the first! :)

  15. Hi,

    I have the like button appearing, but when clicking nothing at all happens??

    Please can you advise on this…
    I even installed the Facebook ‘Like’ plugin and had exact same issue.

    Thanks

      • Ok! Forget it! Since IE jumps every time I paste something, I must have doubled “the-content” part somehow.

        Replaced the old single.php, pasted again your code (both before and after “the-content” and works great either way!

        A million thanks for the code!

  16. thank you very much, i am starting to learn wordpress…and here i found your site very helpfull for begginers…keep it up…

  17. Is there a way to show on the sidebar which posts have the most likes on Facebook. I think it would be neat to see which ones are shared most often.

  18. I addedd the button to my code and it appears in my blog posts. however when I poke it, my facebook profile does not reflect that I like it? Am I doing something wrong? I should see that I like it my feed, am I correct?

  19. I have added the code on single.php , but the button doesn’t appear on all my post.
    If I add the code on every post (from HTML tab), the button appear but encountered problem.
    Why this happen? Is it depend on the theme?

    • It will appear on all single post pages. If you mean that you want to show it on all pages in your category pages or your index pages, then you would need to paste the code in your index.php inside the post loop.

      Admin

      • No, I mean doesn’t show in my posts not pages. Or maybe I placed in wrong part of single.php. Is it possible to paste the code in any part of single.php?
        Thanks.

  20. This is probably a stupid question, but are the instructions you gave relative to the small “thumbs-up” graphic and text (showing 184 people liked this. Be the first of your friends) at the top of this post? Or are they for the larger square graphic appearing to the left of your post (the one appearing underneath your tweetmeme button that says 45 shares).

    I’d like to just have that larger square graphic on my blog and have it appear next to my tweetmeme button and I’m wondering how to go about that? Is there a tutorial you can direct me to?

    Thank you so much for any guidance!

      • Thank you – I did as you suggested and found that tutorial and left you a comment on it as I was unsuccessful in getting it to work. :(

  21. I added the code however if you go to the individual post it gets apage that only shows the facebook “like” button and does not take the viewer to the actual post. So now if a viewer goes to the post they lose it. Any suggestions?

  22. Hi to everyone,

    I see more blogs use only the button and the number of persons who like without the phrase “be the first….”

    how is it possible?

    thanks

  23. I have noticed many sites have added the button to the top of the page. But isn’t it a better idea to place the button at the bottom of the page, allowing readers to click without scrolling up after they have finished reading the article ?

    • Yes just add it after the_content php part of your post … At the bottom of the loop. It can be added anywhere in the loop .. doesn’t have to be at the top.

      Admin

    • Don’t know a lot about Atahualpa theme very much. Please ask in their support forum, or you contact us via email and we can take a closer look at your site.

      Admin

      • Re: Atahaulpa – I had the same issue as Heather. Solution: In Dashboard, go to Appearance – Atahaulpa Theme Options – Style and edit center column. Paste it in “The LOOP” section. Works like a treat!

  24. Been noticing this Facebook like button appearing on more and more sites lately and think it’s a great idea. Time to see if I can implement this now… WITHOUT completely destroying my blog (you’d be surprised how close I’ve come multiple times once I start messing with the code – programmer FAIL).

  25. Love the article but I have encountered some problems. I don’t know where to find the single.php file? lol. Could you guide me? I use wordpress.com and I’m not sure if that makes a difference.

    Thanks!

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.