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

177 CommentsLeave a Reply

  1. Vishwas anand

    This is my single.php file. Please tell me where to add the code.

    ” . __( ‘Next’, ‘twentyfifteen’ ) . ‘ ‘ .
    ” . __( ‘Next post:’, ‘twentyfifteen’ ) . ‘ ‘ .
    ‘%title’,
    ‘prev_text’ => ” . __( ‘Previous’, ‘twentyfifteen’ ) . ‘ ‘ .
    ” . __( ‘Previous post:’, ‘twentyfifteen’ ) . ‘ ‘ .
    ‘%title’,
    ) );
    1
    // End the loop.
    endwhile;
    ?>


  2. j.siurivera

    Thanks so much for the tutorial! However I couldn’t seem to get the Like button to show up on post.
    I’ve been pasting the iframe code in between

    and (iframe code paste here)

    and some other locations before the end loop but still not coming out. Please help!

    Here’s the single.php file for my theme (Eryn)

    Thank you!!

    • j.siurivera

      Sorry just realized the php didn’t come out… here it is:

  3. xuamox

    Works but it is not responsive. Are there any other options for a responsive design?

  4. Manu Raj

    Thank you

  5. Santiago

    I get an Error 404 page when i use the share button. Can you help me please?

  6. Rebecca

    Thank you to the people who asked ‘the dumb questions.’ The answers helped me sooo much. Very happy! Thanks guys.

  7. cathal butler

    Can’t get code to work…..below is copy of code from me single.php page. Where should the code be pasted

    #content{margin-left:18px;}

    <div class="post" id="post-“>

    <?php the_content('Read the rest of this entry »’); ?>

    Pages: ‘, ‘after’ => ”, ‘next_or_number’ => ‘number’)); ?>

    <?php the_tags( 'Tags: ‘, ‘, ‘, ”); ?>

  8. Emmeline Jane

    Hi!

    I’m currently tying to get the facebook insights to work through your code and plugin, however I can’t for the life of me figure out how to put this ‘proper’ facebook like code in…..!!

    This is the code for my ‘singular.php’.. the theme I’m using is Hatch.

    <div id="post-” class=””>

    <?php echo apply_atomic_shortcode( 'byline', '’ . __( ‘By [entry-author] on [entry-published] [entry-edit-link before=” | “]’, ‘hatch’ ) . ” ); ?>

    <?php the_content( __( 'Continue reading →’, ‘hatch’ ) ); ?>
    ” . __( ‘Pages:’, ‘hatch’ ), ‘after’ => ” ) ); ?>

    Please let me know where to put the code! I’ve tried it every where, around the ( have_posts) etc…

  9. Amy

    How do I add a facebook “like my page” button on my posts? I saw the configuration and I have the two codes but I have no idea about Javascript, etc?? Thanks!!

  10. Karen

    Hi thanks for the tutorial! I got it to work on my site but for some reason when I “like” a post it doesn’t show up in my FB feed. Any idea if I did something wrong?

    • Editorial Staff

      Sometimes if you excessively like posts from one site, then FB tends to temporarily block it. On the other hand, look in your activity feed to see if it is going there.

      Admin

  11. Juvy

    Hi, WPBeginner,

    Can I ask your help. I am new of WordPress. I have a big problem on my website. Please help me how to resolve. I’m begging you. This is my website http://www.mymovietube.com and it was broken.
    This is the error I received:

    Parse error: syntax error, unexpected ‘<' in /home/mymovie/public_html/wp-content/plugins/facebook-social-plugins/widgets/like-button.php on line 2

    Please let me know how to fix this.
    Thank you.

    Need Help,

    Juvy

  12. Michael

    Is Facebook Insigts also working with the html5 version of the like button or just with the xfbml version? Both versions are working with the same javascript.
    Great article by the way. I’m going to implement that into my website. Thanks.

  13. Jake

    I was wondering if you could tell me how to customize the image and description that shows on Facebook when you like the site or possibly point me to a article that discusses this, I am having the hardest time trying to figure that part out. Thanks!

    • Editorial Staff

      Use the WordPress SEO by Yoast plugin. It adds og: (Open Graph) tags in your theme. The meta description you specify for your post will then end up being the description. The post thumbnail you attach will end up functioning as the thumbnail. Hope this helps.

      Admin

      • Jake

        YES!!! This site rocks!!

  14. garrick1234

    Where does one find the single.php file?  Sorry I know that sounds pretty dumb, but I am (sometimes)

    • wpbeginner

       @garrick1234 No such thing as a dumb question. You will find it in your FTP folder /wp-content/themes/yourthemename/Or in your WP-Admin go to Appearance > Editor and find it there.

  15. Ginger

    How can you enable users to add their own comments to their recommendation at the time of posting?

    • wpbeginner

      When the user clicks, a comment box should just open. Specially if you are using the FBML version.

  16. angie

    thank you for the layout=”button_count”!!! i’ve been looking for that everywhere!

  17. Editorial Staff

    Hey,

    Use WordPress SEO by Yoast and enable the social section. Or just install and activate Simple Facebook Connect… don’t have to do anything else, and it will work.

    Admin

  18. tingmike

    Thanks. One problem that I have is that the button doesn’t align with the Google+ and Pinterest buttons. It’s just two pixels too low compared to the other buttons. Any idea how to make them align to the same horizontal alignment?

    • wpbeginner

       @tingmike You can add CSS classes to make sure that it works.

  19. Fran Dorf

    Where do I find the “post loop” in the single.php file? I’ve tried pasting your code in various places and nothing happens!!!

    • Editorial Staff

      Post loop is the code which says while have posts, the post etc. You want to post this code before the endwhile;

      Admin

    • wpbeginner

       @Fran Dorf You have to look at while have_post, the_post

  20. Kate

    While these instructions appear straightforward, they are of no use to someone who does not know how to “open your single.php file in your theme’s folder.” While I am on the internet all the time, I have next to zero knowledge of html. I have added code before, but I need instructions on how to get to the code in the first place. I cannot find anything anywhere on wordpress about a “single.php” file. Please help. I really want readers to be able to share my posts on Facebook, Twitter, and through e-mail.

    • wpbeginner

      If you are unaware of how to open your single.php file, then perhaps you should utilize one of the many free plugins that add a facebook like button to your site.

  21. Tierney

    Hi, I posted the code on my site and it worked. However, the friend icon is not staying. When i refresh the page, the friend icon disappears. I want all of the friend that clicked the like button to remain so I would know who clicked the like button. I need their names for the prize drawing. Can you help? Here is my code:<iframe src="http://www.facebook.com/plugins/like.php?href=ID)); ?>&layout=standard&show_faces=true;width=450&action=like&colorscheme=light” scrolling=”no” frameborder=”20″ allowTransparency=”true” style=”border:none; overflow:hidden; width:450px; height:60px”>

    • Tierney

      sorry. I tried posting my code but showed up as that WP beginner. My apologies

    • wpbeginner

      your code is right… it seems like that its some sort of FB glitch that its not recording your likes.

  22. Megan at Fiterature

    Hi – this is not working for me. I copy and pasted exactly what is above into my single.php section. I am using the Twenty Eleven theme. When I Update File and then check my website…no Like button. What am I missing?

  23. papayacansada

    I’ve been having some headaches with this thing, all I want is a facebook like button on the homepage, I got that but the problem is that when the button is clicked it will like the most recent post and not the main page, after many attempts at the moment I have the code outside the loop, in the header so it displays pretty much everywhere, it seems that even this way when I’m on a single page the button work as supposed and likes go to the single post, my concern is the main page, I need it to like mydomain.com and not the latest post when I’m on the homepage.

    • wpbeginner

      @papayacansada where it says href in the code. Replace the php code with your site domain.

  24. jenniferdoser

    This worked great – thanks! I’m just having 3 issues. (1) When I like a post, it shows the following text next to the thumbnail:You may use these HTML tags and attributes: (2) I would like to have the comment box drop down when someone clicks the like button, as it does on this site and I can’t seem to find any documentation on that.

    (3) I tried to access insights after installing the Open Graph plugin, but I get this error message when I try to add insights for the blog:No admin data found at root webpage http://www.firelilyphotography.com/. Insights requires admin data at this root webpage for the specified URL http://www.firelilyphotography.com/blogWhat admin data do I have to add for insights to work?

    Thank you!

      • jenniferdoser

        I’m using the XFBML way and I’m still not quite there. I think the main issue is that when I first activated the plugin, I used my business page Facebook ID instead of my personal ID. I’ve since updated the ID, but I still get an error when I like a post:The app ID “73464248836” specified within the “fb:app_id” meta tag was invalid.This is my business page ID. I tried deleting the plugin and starting from scratch, but that’s not working. How can I get WP to recognize the new ID?

  25. robolist

    @wpbeginner thanks for that :) For some reason i was thinking it wouldnt work. My college placed the codes for share buttons there before but when clicked they would ‘like’ all of the posts together. Maybe he didnt use the get_permalink function. Although i am sure i told him to use it. but it is working now so thank you so much…

  26. kellydiek

    Are you aware of a plugin or even the possibility for this… you have a blog post with the like button on it. Currently has 15 ‘likes’. Let’s say you edit your blog post with updated information. Can you force facebook to repost the blog link to the wall of the users who already ‘liked’ the post previously? (So they know it’s been updated). Hope that makes sense. Requested by a client today and I’ve never heard of such a thing!

  27. wpbeginner

    @robolist Are you using a theme framework?? If not then it shouldn’t be very hard. Place the code above inside your loop on the index.php or loop.php or your archive.php file…

  28. robolist

    Fantastic tutorial guys… Just like all of your tutorials throughout this website, they are all very easy to follow. Great stuff :)

    I have been developing a new blog for some time now and am working on a customised theme. We have placed several social share buttons on each post very similar to how you have suggested here. I chose to do it manually rather than using a plugin because i dont seem to be able to get exactly what i want from the plugins whether it be the correct share buttons i want or the lack of styling options with the plugin.

    Placing the buttons manually allow me to use what i want and style them how i want. The only problem is, for the life of me i just cant figure out how to get the buttons to appear in the loop with the excerpt.

    I would be extremely grateful if you could point me in the right direction.

    Many thanks in advance.

  29. filipstrbad

    when i add the code to single.php it only shows the like button on the new posts and not the old ones. can i add it to the old ones too?

  30. wpbeginner

    @JustinElia This tutorial is for adding the like button for each WordPress post… if you want it to link to your facebook page, then simply change the href to facebook.com/yourfanpage

  31. JustinElia

    This may be a very stupid question. I am using like buttons on my site and have tried various plugins and everything,however, how does one link the facebook like button with your page on your posts? Example : I go to like a certain post on facebook on my site and it says “So and So liked http://www.bigbackpacker.com post about blah blah blah” It doesn’t link to my facebook page for my blog. I hope this isn’t too confusing and any help would be appreciated, thank you.

  32. ssfutrell

    I uploaded the facebook like button plugin. It is on the bottom of my posts. I want it at the top of all posts. How do I change it to be at the top of post. Can’t figure that out. I hope that you haven’t answered already. I need very plain instruction. Thanks.

  33. wpbeginner

    @seocatalysts Use the facebook like box plugin…

  34. seocatalysts

    Thanks for inform me about how to add like facebook button? and I did it but still My confusion is that how can i show that how many people like my blog? For this problem solve any script available….Any help would be appreciate…..

  35. SeviGadeaGimenez

    I like to ask you how i can do to center the like button, i mean that i have the button at the left of the page but i’d like to have it on the center.

    thanks for all, and forgive my poor english

  36. wpbeginner

    @debbie.mccormick You can only paste functions in your custom-functions.php files…

    If you notice in our directions we suggested that you paste it in your single.php file. However, I understand that you are probably using a child theme for thesis that is why you don’t have access to single.php file.

    You need to run this code as a function. Or use a plugin.

  37. debbie.mccormick

    HELP I just put this code in my custom PHP folder and now my blog is gone.

    I get this message:

    Parse error: syntax error, unexpected ‘<‘ in /home/debmcc4/mccormickmadness.com/wp-content/themes/thesis_181/custom/custom_functions.php on line 118

    I copied and pasted it right in so I can’t see how I could have put anything in incorrect. Please help me!!

  38. wpbeginner

    If you follow our article about how to add open graph meta data, then it asks you to link your facebook account with your site. Then you will go to:

    http://facebook.com/insights << There you can add your website. If your account is listed as it should, then it will show you all sort of cool insights about your site.

  39. kiendlam

    How exactly do you see who actually clicked on the Like button. It usually shows one or two names and then a number, but I can’t seem to click anywhere to see who has liked the post. Can you help? Thanks.

  40. wpbeginner

    @infinitywealth.carmen yes… u cannot install any plugin on the free WordPress.com site.

  41. infinitywealth.carmen

    @wpbeginner what about smart sharing plug in? still need self-hosted wordpress?

  42. wpbeginner

    @infinitywealth.carmen Nope.

  43. infinitywealth.carmen

    So there’s no way to add FB like box in the free version of wordpress? I have tried to add both types to a html widget but it won’t work

  44. wpbeginner

    @anthony_garcia Use the plugin that we recommend in this article. Facebook Open Graph Meta Data. That will fix the issue.

  45. kaniayubu

    For some reason I have been unable to get the XFBML version of this code to work. The iframe version works perfectly but as you mentioned in your other post, the send button doesn’t work in the iframe version. Could there be any additional steps to get the xfbml version of it working. I don’t even see a Facebook like icon when I use the xfbml code. Any help would be greatly appreciated. Thanks.

  46. wpbeginner

    @artist74 No need to do anything else. It will be like that for all your posts.

  47. artist74

    Many thanks for your incredibly speedy reply. I had to play around a bit and now it’s working for me (bottom of the post on my blog). :-)

    Will this now be as default (so for every post, this is what I want) or do I need to add anything else?

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