Tag Archive: facebook comments for wordpress

Facebook Comments In WordPress

March 24, 2011

This post is dedicated to using Facebook’s Developer Code and implementing it into your comments loop through PHP. There is a WordPress plugin already dedicated to using Facebook comments here. This is the ‘cleaner’ way to implement Facebook Comments on your blog. After upgrading to the ‘newer’ version of this plugin, i started experiencing problems so I found a workable way around using this gaudy plugin.

This is step by step instructions on how to put Facebook Comments into your comments loop for WordPress. You need to know about PHP, you need an FTP editor, and you need some sense…. I will not help support after this post.

Step 1: Develop a Facebook App ID

You are required to do this anyway if you use the plugin listed above, so it’s basically a necessity. Go to Facebook/Developers and set up a new application. It’s a few tedious steps to gain access to Facebook Comments.

The important thing is you are given a Facebook Application ID, API Key, and Secret.

Step 2: Get the Facebook Comments Code

Facebook already has a code generator set up to incorporate Facebook comments for your site.

Go to the Facebook Comments Generator

The Problem?

This forces you to use a URL that is specific to one site. It doesn’t change per post once in your WordPress loop, so basically when someone posts a comment, no matter for what post, it displays in the comments section for every post. That does us no good. So for now, just grab the code, and save it somewhere.

Step 3: Find the proper place to put the code

You need to open your FTP editor at this point, go to your theme’s directory, and find ‘comments.php’ Hopefully you’ve edited this at some point before, or have some clue about what you are doing. I pray you do. The comments.php is part of the ‘WordPress Loop’ that is basically a dynamic loop process that gathers all of the page’s content before displaying it.

Here’s what I did

I had comments turned off for my blog in ‘Discussion’ settings in WordPress. It makes it easier for this project I feel, so I would recommend doing so. If you have some familiarity with this process, you understand you have a lot of control as to where you put this code in your loop.

Here’s what you do

Find the {else} loop in your comments.php file for displaying something when comments are turned off. Typically it involves a phrase like “Comments are Closed” followed by some kubrick php syntax. You are looking for what is outputted when the comments are off.

Find that code and right above it, the line before, place your Facebook Comment generated code.

Step 4 : Make the code dynamic

So like I said before, this code is only generated for a site, not a specific post. We need to make the code dynamic in order to keep comments separated for individual posts so they don’t carry over. Here is what your code should be like :

Now the Changes

Well, for starters, the code you get generated might not prompt your application ID. Make sure you place it in place of my “######” symbols.

Second Change

We will make the script dynamic. Where “YOUR_URL” was placed probably reads the main site’s URL. That’s cool, but we want it to read the specific blog posts PERMALINK, for every post. So… we use the WordPress PHP loop calling for the permalink :

Place that instead. This tells the script to load comments specifically for that blog’s permalink now, making each script specific to that individual post! BAAAM!!!

It should read like :

Just make sure your APP ID is placed after “=” but before “&amp”. Then place the PHP permalink call function after the “href=” and you’re done!

It’s important to note that this code has MANY places it can be implemented. You do not need to place it in the comments loop if you don’t want to. You can place it in the single.php file, the page.php file, the archives.php file, or the index.php file. The only qualification you need is that this script remains IN THE WORDPRESS LOOP, otherwise the PHP will not work. Experiment with it, and see what works best.

Hopefully this helps serve as an alternative for people who have some moderate coding ability and don’t want to resort to WordPress plugins for everything. Check out the Facebook Developers Comments instructions though. There are some good tips on how to reference specific things, how to control admins, and so forth.

And of course, comments are closed for this. I’m sorry but I don’t do support.