Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Display the Facebook Comment Count in WordPress Theme

Last updated on by
Follow WPBeginner on YouTube
How to Display the Facebook Comment Count in WordPress Theme

Recently, we showed you how to setup facebook comments for WordPress. One of the downside of using that plugin is that it overtakes all WordPress comment_count functions, and it outputs a facebook branded version of the comment count. This may cause issues to your WordPress design specially if you are using a comment bubble to just display the number. In this article, we will show you how to display the facebook comment count in your WordPress theme.

All you have to do is paste the following code in your theme file where you want to display the comment count:

<fb:comments-count href="<?php echo get_permalink($post->ID); ?>"></fb:comments-count> Comments

Hope you will find this handy while designing your WordPress themes.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • Ivan

    Hi
    Do you know who to get it to say Leave Comment if the count is 0?

    <?php if ( (<fb:comments-count href="ID); ?>”>) > 0 ){
    <fb:comments-count href="ID); ?>”> Comments } else{ echo (“Leave a Comment”; ) }

    something like that I guess?

    • Chris

      I would also like to know how to show some text that reads ‘Be the first’ if there have been zero comments made. How is this possible?

      • http://www.wpbeginner.com/ WPBeginner Support

        check your comment loop in comments.php you can use get_comments_number(); to check the number of comments.

  • Charlotte

    So stupid question from beginner. I have managed to install the FB comments and disable the WP comment box. :D

    Now, you say the “theme file” which file is that? Not functions.php I guess….maybe theme theme-comments.php ?????

    • Charlotte

      I see now these solutions are fo rfacebook-comments-for-wordpress.3.1.3.zip.

      As I have WordPress 3.4.2 I could not use that version.
      I am using Facebook Comments facebook-comments-plugin.2.0.3.zip

      So I guess I am stuck with no solution for getting the FB comments to be included within the new comments count….aaaa….

  • http://www.demaze.it/ Benjamin

    There is an error, the right code is <fb:comments-count href=<?php echo get_permalink($post->ID); ?>></fb:comments-count> Comments without this “” ! It doesn’t work with HTML5 Facebook comments.

  • http://counterforsite.com/ counterforsite

    Well using bubble count is good idea to display your popularity and it makes page more attractive.I have used your script for my WordPress blog but it doesn’t show anything.

  • http://www.dannyiovane.com/ Danny

    Actually, you are missing the fbcomments and fbroot divs and the script reference to go with this. Which is why some people aren’t getting the wanted results, as this piece of code alone won’t do much.

    • http://www.wpbeginner.com/ wpbeginner

      The fact that they have Facebook Comments on the page should mean that they have those scripts in place. Which is the reason why we didn’t add it in this article.

  • seyko

    is there a way to style the display of the comment count?

    • http://www.wpbeginner.com/ wpbeginner

      You can probably try to override the style from your style.css with !important tags.

  • JoseluisVeraCastillo

    Is it possible to sum WP plus FB comments?

  • deverzamelaar

    On my website it doens’t show a thing. I use the facebook comments for wordpress and I use version 2 only. When I set the native comment count it show the right amount of comments but when I try to insert the comment count manually it shows nothing. It only creates a class comment_count_zero. But i’m sure there are comments there.

    Anyone who could help me?

    • Dogan Kutbay

      This trick doesnt work anymore. Facebook changed it.

      • http://www.wpbeginner.com/ WPBeginner Support

        @deverzamelaar and @Dogan: This code may not work on some HTML5 websites. Instead you should try this code:

        <iframe src="https://www.facebook.com/plugins/comments.php?href=example.com&permalink=1" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:16px;" allowTransparency="true"></iframe>
        
  • JeffHarkey

    For our site (www.firenews.net), it only shows “0″ even when a Fb comment has been left.

  • TaylorJ.Thompson

    What if you’re displaying the comment count on an archives page? The method above doesn’t work.

  • TaylorJ.Thompson

    What if you’re displaying the comment count on an archives page? The method above doesn’t work.

    • wpbeginner

      @TaylorJ.Thompson The key to this code lies within the actual href << If you can pull the appropriate URL for each post in that code, then sure it would work in the archive page.

  • TaylorJ.Thompson

    What if you’re displaying the comment count on an archives page? The method above doesn’t work.

  • TaylorJ.Thompson

    What if you’re displaying the comment count on an archives page? The method above doesn’t work.

  • ciesla504

    RT @wpbeginner How to Display the Facebook Comment Count in #WordPress Theme – http://t.co/1Acnv1P #WordPress #design #business