Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Add Facebook Like Button in WordPress

Do you want to add a Facebook Like button in WordPress?

A Facebook Like button on your WordPress website can make it simple and easy for users to like and share your content. This can help you increase engagement and get more followers.

In this article, we will show you how to add the Facebook Like button in WordPress.

How to add Facebook like button in WordPress

Why Add a Facebook Like Button in WordPress?

Facebook is one of the most popular social media platforms in the world. Many businesses use Facebook to connect with their customers and promote their products.

Adding a Facebook Like button to your WordPress website can help drive more engagement. It also encourages people to share your content on their Facebook profiles and attract new users to your site.

You can use the Facebook Like button to increase your social followers and build a community. It helps raise awareness about your products and services and boosts conversions.

With that in mind, we’ll show you how to add a Facebook Like button to your WordPress website. Here’s a quick overview of the methods we’ll cover in this guide:

Ready? Let’s see how to add a Facebook Like button in WordPress using a plugin or custom code.

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

In this method, we’ll use a WordPress plugin to add a Facebook Like button. This method is very easy and recommended for beginners.

The first thing you need to do is install and activate the BestWebSoft’s Like & Share plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, you can go to Like & Share » Settings from your WordPress admin panel.

Like and share plugin settings

Next, you’ll need to add a Facebook ‘App ID’ and ‘App Secret.’ If you don’t have this information, then simply follow the steps below.

How to Create a Facebook App ID and App Secret

In the ‘Settings’ panel, go ahead and click the ‘Create a new one’ link under the ‘App ID’ or ‘App Secret’ field in the Like & Share plugin.

This will take you to the Meta for Developers website. We suggest opening the website in a new tab or window because you’ll need to open the Like & Share settings page in your WordPress dashboard to enter the app ID and secret.

From here, you’ll need to select an app type. Go ahead and choose ‘Business’ as the app type and click the ‘Next’ button.

Choose your app type

Next, you’ll need to provide basic information about your app.

You can enter a display name for your app and be sure that the correct email address appears under the ‘App contact email’ field. Facebook will automatically pick the email address of the account you’re currently logged in to.

There’s also an option to choose a business account. You can leave this on ‘No Business Manager account selected’ and click the ‘Create app’ button.

Enter basic information for app

Then, a pop-up window will appear. Here, Facebook will ask you to re-enter your password.

This is a security measure to prevent malicious activity on your account. Go ahead and enter your Facebook account password and click the ‘Submit’ button.

Reenter your Facebook password

After that, you’ll see your app dashboard.

From here, you can head over to Settings » Basic from the menu on your left.

Go to basic settings page

Now, you’ll want to expand the ‘Settings’ dropdown and click ‘Basic.’ Here, you will see the ‘App ID’ and ‘App Secret.’

You can now enter this information in the Like & Share plugin settings.

Copy the app ID and secret

Finish Up Customizing Your Facebook Like Button

First, you’ll want to copy the ‘App ID’ and head back to the tab or window where you have the Like & Share » Settings page opened. Then, simply enter the ‘App ID’ in the respective field.

Now, you’ll want to repeat the step by copying the ‘App Secret’ data from the Meta for Developers page and pasting it into the Like & Share plugin settings.

Customize your Facebook like button

Once you’ve done that, you can choose whether to show the Facebook Like button along with the Profile URL and Share buttons.

There are also settings to edit the Facebook Like button’s size, its position before or after the content, and alignment.

More customization options

If you have enabled the Profile URL button, then you can scroll down to the ‘Profile URL Button’ section and enter your Facebook username or ID.

When you’re done, don’t forget to save your changes.

Now, the plugin will automatically add a Facebook Like button to your WordPress website and position it based on your settings.

You can also use the [fb_button] shortcode to add the Facebook Like button anywhere on your site.

That’s all! You can now visit your site and see the Like button on each post.

Facebook like button preview

Method 2: Manually Add a Facebook Like Button in WordPress

Another way to add a Facebook Like button is by using custom code. However, this method requires adding code directly to WordPress, so we recommend it only for those comfortable with code editing.

In this section, we’re going to use the WPCode plugin, as it makes it simple for anyone to add code to their WordPress blog.

But first, you’ll need to visit the ‘Like Button’ page on the Meta for Developers website and scroll down to the ‘Like Button Configurator’ section.

Get code from Facebook developer site

Next, enter your Facebook page URL in the ‘URL to Like’ field. This will connect the Facebook Like button to your page.

After that, simply use the configuration to choose the Like button layout and size. You will also get a preview of the Like button.

Once satisfied with the preview, go ahead and click on the ‘Get Code’ button. This will bring up a pop-up window that shows two code snippets under the ‘JavaScript SDK’ tab.

Copy the SDK code

Please note that directly adding these code snippets to your WordPress theme may break your website. Plus, they will be overwritten when you update the theme.

That’s why we recommend using the WPCode plugin. This plugin lets you paste code snippets into your website and easily manage custom code without editing the theme files directly.

To get started, you’ll need to install and activate the WPCode free plugin. For more details, please see our guide on how to install a WordPress plugin.

Upon activation, you can head to Code Snippets » Header and Footer from your WordPress dashboard.

Then, you’ll need to copy the first code snippet and add it to your WordPress theme’s header.php file right after the <body> tag. Simply copy the code and enter it in the ‘Body’ section.

After completing this process, don’t forget to click the ‘Save Changes’ button.

Add first code to header section

Next, you’ll need to copy the second piece of code and paste it into your WordPress site to display the Facebook Like button.

To do this, you can go to Code Snippets » + Add Snippet from your WordPress admin panel. Or, simply click the ‘Add New’ button in the WPCode dashboard.

Click 'Add New Snippet' in WPCode

On the next screen, WPCode will allow you to select a snippet from the pre-built library or add a new custom code.

Go ahead and choose the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button.

Add custom code in WPCode

After that, you can give your custom code a name and enter the second code snippet under the ‘Code Preview’ section.

Make sure to click the ‘Code Type’ dropdown menu and select ‘HTML Snippet’ as the code type.

Enter second code and select code type

Then, you can scroll down to the ‘Insertion’ section and select where you’d like the Facebook Like button to appear. For example, let’s say you want it to appear before the content.

Simply click the ‘Location’ dropdown menu and choose the Insert Before Content option under ‘Page, Post, Custom Post Types.’

Select location of like button

Once you’re done, you can click the ‘Save Snippet’ button.

You’ll also have to click the toggle and switch it from ‘Inactive’ to ‘Active.’

Save and activate code snippet WPCode

That’s it. A Facebook Like button will appear on your website after you enter the code.

What Is Open Graph Metadata & How to Add it to WordPress?

Open Graph is metadata that helps Facebook collect 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 it may sometimes show an incorrect thumbnail when shared.

If you are already using the All in One SEO (AIOSEO) plugin, then this can be easily fixed by visiting All in One SEO » Social Networks and clicking on the Facebook tab.

Next, click the ‘Upload or Select Image’ button to set a ‘Default Post Facebook Image’ if your article doesn’t have an open graph image.

Upload default Facebook image

Besides that, you can also configure an open graph image for each individual post or page.

When editing a post, simply scroll down to the AIOSEO Settings section in the content editor. Next, you can switch to the ‘Social’ tab and see a preview of your thumbnail.

AIOSEO product social sharing settings

Now, you’ll want to scroll down to the ‘Image Source’ option. Then, go ahead and choose an open graph image for your post.

For example, you can select ‘Attached Image,’ ‘First Image in Content,’ or ‘Custom Image’ to be used as an open graph thumbnail.

Image source for open graph

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

We hope this article helped you learn how to add a Facebook Like button in WordPress. Next, you may also want to see our guide on how to display Facebook page reviews in WordPress or our expert picks of the best social media plugins for WordPress.

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. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

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

178 CommentsLeave a Reply

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. wpbeginner

    @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!

  3. dekanfari

    Can I align it to left?

  4. Ovidiu

    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?

    • Editorial Staff

      You need to add the Open Graph Meta Data to the site. We have edited the article. Look for the NOTE.

      Admin

  5. tyasmedika

    Nice post…
    How to add facebook like button in wordpress.com?
    Thanks.

    Please, Visit my blog. ^_^

  6. Dror

    Hi,

    Is there a way to add the like button to the comments on a wordpress blog?

    Thanks

    • Editorial Staff

      Yes, you can have the like button on each comment by retreiving the comment permalink rather than the post permalink.

      Admin

  7. Redefining

    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?

  8. Ruby

    Thanks a lot I was just looking for that………

  9. Aaron Grey

    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?

    • Editorial Staff

      It shouldn’t cause issues… both won’t update simultaneously, but it will display the same count on each page refresh.

      Admin

      • Aaron Grey

        I kind of thought so. I just never heard anyone mention doing this in any tutorials. Thanks for the info.

  10. Dimitris

    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.

    • Editorial Staff

      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

  11. Alvin

    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?

  12. Aaron Torng

    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

    • Editorial Staff

      Use the Like Box instead of the Like Button on the main page, and put it in your sidebar.

      Admin

  13. Sipovics

    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!

    • Editorial Staff

      You need to paste the codes mentioned in this post INSIDE THE LOOP. If you post it outside the post loop, then it will not work.

      Admin

  14. charle

    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?

    • Editorial Staff

      Yes thats true. You are very limited with WordPress.com site. The solution is move to a self-hosted setup. Utilize our Free Setup service.

      Admin

  15. Joe

    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

    • Editorial Staff

      This is an iframe code, so it should work because we are using it on our site.

      Admin

  16. drowan

    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!

    • drowan

      my permalink structure at this time is /%category%/%postname%/ for reference. All the ‘likes’ I’ve tested only link to the parent site.

    • Editorial Staff

      The code that we have is the same one running on this site. As long as you post it in the loop, it should like the page that you are on.

      Admin

  17. wilson keenan

    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

    • Editorial Staff

      We are not using Meta tags in the header at the moment, so it is just an iframe.

      Admin

  18. Aurora

    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!

    • Editorial Staff

      Don’t think that there is a Facebook API that lets you like the layout…

      Admin

  19. Ash Robbins

    Great post guys, so simple to add in and configure. Nice work.

  20. sanjaperic

    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! :)

    • Editorial Staff

      It is a very weird problem. Normally it won’t show you pictures unless your friends like it, but it certainly shows the count.

      Admin

  21. Huw Rowlands

    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

    • Editorial Staff

      Don’t know what could be the issue. We have the exact same code running on our site… and it is working fine.

      Admin

    • Paul

      Working perfectly now. Must have been a problem from Facebook’s end.

  22. Rakibul Islam

    This seems to not working on my site. It showing error after clicking the Like button. :(

    What can i do now?

    • Editorial Staff

      We are using this code on our site, so don’t know what could be causing the error. Can you please specify what error it is.

      Admin

  23. Janice

    Thanks for the tutorial and great tips inside the comments. Just installed on Atahualpa theme. Great!

  24. Sean Serritella

    All I know is that I tried putting in code for the like button and now I get double posts.

    • Eli

      Same happens to me, had to erase it because it doubled the text of my posts

      • Eli

        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!

  25. agon

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

  26. Sean Serritella

    Dude, what loop? What is a loop? I don’t get what that means. I tried pasting the code in the single php page but got nothing.

  27. Jason Fonceca

    Fantastic! I know this may seem like a useless comment, but I really am thrilled to find this tutorial. Much appreciation.

  28. Lindsay

    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.

  29. Mark

    I posted it in my style.php so I am not sure if that is what you mean by putting it in my loop?

    • Mark

      sorry single.php file is rhe one I changed

  30. Mark

    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?

    • Editorial Staff

      Yes you should see that you like it in your feed. Are you pasting the code inside your loop?

      Admin

  31. Jose

    Thanks for sharing. How did you make your retweet and facebook share buttons to remain permanent on your blog?

    • Editorial Staff

      We are using a plugin called Smart Sharing. Do a search on our site and you should be able to find it. It is exclusive for WPBeginner users.

      Admin

  32. Janek

    thanks for the good tutorial Facebook Like Button in WordPress
    helped me very much!

  33. Que

    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?

    • Editorial Staff

      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

      • Que

        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.

  34. Andrea

    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!

    • Editorial Staff

      This tutorial is about the like button. Just use the search button on this site and look for Facebook Share button and you will find the tutorial for that.

      Admin

      • Andrea

        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. :(

  35. dillon

    The like button is the best little added feature to a site thanks for the lesson.

  36. Sara

    Works great! I narrowed the height to get rid of some white space it caused, but that was the only tweak.

  37. Jan Weiss

    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?

    • Editorial Staff

      Have no idea what you are talking about. Please use our contact form and show us what you are talking about by linking to your site.

      Admin

  38. Ciociaria

    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

    • Editorial Staff

      You need to change the layout parameter to button_count as mentioned int he article.

      Admin

  39. Titanas

    Hey,

    What about adding the site’s URL after the post title? Something like this: X likes Y on Z.com

    • Editorial Staff

      You don’t get to control that. It is facebook who is doing that, and they only display page title.

      Admin

  40. Danang Sukma

    Finaly iam found plugin like the float stuff in your site. Thanks for your share.

  41. Mike

    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 ?

    • Editorial Staff

      It is entirely up to the blogger. You can try it on your blog and see which placement works best for you :)

      Admin

  42. Tiffany

    Is there a way to make it display at the bottom of the post instead of the top?

    • Editorial Staff

      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

  43. Heather

    Unfortunately, I don’t have a single.php file in my Atahualpa theme. I’m not sure where else I could put the code. Any ideas?

    • Editorial Staff

      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

      • Stu

        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!

  44. Stu

    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).

  45. Amanda

    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!

  46. jeh

    Just what I was looking for. Thanks

  47. hydir

    Thanks for this tutorial.
    I really looking how to implement it and found the answer here.

    Great!

Leave a Reply to robolist Cancel 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.