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. This is my single.php file. Please tell me where to add the code.

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

  2. 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!!

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

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


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

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

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

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

  5. 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…

  6. 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!!

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

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


  8. 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 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,


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

  10. 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!

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


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

    •  @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.

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


  13. 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?

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

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

  15. 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="; ?>&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”>

  16. 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?

  17. 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 and not the latest post when I’m on the homepage.

  18. 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 Insights requires admin data at this root webpage for the specified URL admin data do I have to add for insights to work?

    Thank you!

      • 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?

  19. @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…

  20. 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!

  21. @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…

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

  23. 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?

  24. @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

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

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

  27. 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…..

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

  29. @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.

  30. 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/ 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!!

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

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

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

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

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

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