Migrating Facebook Comments to wordpress without any plugin

If you were using Blogger or wordpress for your blog, you maybe wondering how will you migrate the Facebook comments of your blog readers to your new blog. This post shows exactly how to do it.

Sure, there were a good number of WordPress plugins that allow you to integrate Facebook comments in your blog. I looked a bit of Facebook API, hacked a bit of code, and migrated all the comments without needing a plugin. And here in this tutorial, I will show you exactly how to do so.

First of all, I recommend that you backup your WordPress blog, both the files and the database using a good plugin. Integrating Facebook comments will require editing some WordPress core files, so if anything goes wrong and you need to roll back to earlier state, you can restore the things from backup.

To start with, we need to include the Facebook JavaScript SDK at the start of the page in the <body> section of HTML to load the Facebook API. Go to this facebook developer page and click on the Get Code button. A dialog box will appear as shown below:



Select your application and copy the code from <div id="fb-root"></div> to </script>. Now go to your WordPress admin interface and navigate to Appearance > Editor. Click on the file Header (header. php) and paste the code just after the beginning of tag. Be careful, do not affect any other code.




You may also need to add the fb-admin tag for moderating facebook comments, though thats strictly not necessary. Just after the head tag opens, place this code. Make sure your place your application ID in appropriate place.

When done, click on Update File.

Now the SDK is loaded, we just need to insert the code which will allow us to load the facebook comments in the page. For that, we need a minor edit in a page. From the templates list in the right sidebar, click in the file Single Post (single.php). From your browser’s find function (Control+F), find this code: php get_template_part( ‘content’, get_post_format() ); ?>.

Add the following code just after that line.

You may adjust the data-width according to the theme of your webpage, but make sure that other codes remain the same. Now navigate to the top of the file and just after get_header(); ?>, add the following PHP function.

When done, just click on Update file. You have successfully integrated and migrated Facebook comments in your WordPress blog.




Manikandan is Founder and author of codenread. Tech Blogger by Passion | Computer Science Engineer by Qualification