Integrating Disqus Into WordPress

Integrating Disqus Into WordPress

Tutorial Details
  • Program: WordPress
  • Version: 3.0+
  • Difficulty: Medium
  • Estimated Completion Time: 30 minutes

The comment infrastructure of WordPress is pretty neat and satisfactory for many, but if you need your commenters to connect to your website with social media accounts like Facebook, Twitter, Google and such, you have to install plugins that provide this functionality.

Or you could just use Disqus.

Disqus is a comment system that provides nearly every authentication API including Facebook, Twitter, Google, Yahoo and OpenID. Plus, you can log in with your Disqus credentials (which lets you follow every conversation on every site you commented on) or simply just comment with a name and an e-mail address.

There is an easy way to integrate Disqus into WordPress: You just register a new Disqus account and install the WordPress plugin. It even synchronizes with your native WordPress comments, so you don’t have to worry about your existing comments. And it keeps them synced!

But if you don’t need to sync with the native comments anymore (like me) and if you are an optimization freak (like me) who hates those extra database queries plugins make, or if you don’t care about your existing comments at all and want to start fresh, there is a relatively easy way to integrate Disqus into your WordPress blog.


First Things First: Registering a New Disqus Account

The easiest part of this tutorial: Just head over to Disqus.com and fill this single-page form to register a new account:

Screenshot 1: Registering a new account on Disqus

(Don’t forget to verify your account by clicking the verification link that’s going to be sent to your e-mail address!)


Setting Up the Plugin and Exporting Existing Comments to Disqus

Well, you know the drill: Download the plugin, extract the archive to your plugins folder (or search for “Disqus Comment System” from the “Install Plugins” page of your admin panel and install the plugin from there) and activate it.

Setting Up the Plugin

When you activate the plugin, there will be a WordPress notice with a link to set up your plugin. There, you need to log in with your Disqus credentials first:

Screenshot 2: Logging in after activating the plugin

After that, choose your website. Congratulations, you just installed Disqus on your blog!

Now, click on your Comments page and then the Advanced Options link at the top-right of that page. There are several options to be checked:

Screenshot 3: The options page
  1. Disqus short name: This is the short name which you set while registering to Disqus. It should be automatically set for you when you logged in a minute ago.
  2. The API keys: These are also automatically set for you and you shouldn’t change them. If you accidentally changed or deleted one of these two, visit your profile page on Disqus.com to get the correct API keys.
  3. Application Public & Secret Keys: These are used for single sign-on (SSO) applications. We’re not covering in this tutorial so we’ll pass these.
  4. Where to use Disqus comments on: You may choose to show the Disqus comment system only on your posts which you disabled commenting, or you can enable Disqus for every post. Leave the option as is if you want to show Disqus on all of your posts.
  5. JS output for comment counts: Disqus automatically tries to change the “X Comments” parts of your theme. If it fails, you may need to enable this option.
  6. Disable automatic synchronization: If you don’t want to sync new comments (posted on Disqus) with your native WordPress comments database, check this option and disable it.
  7. Disable server side rendering: This option allows you to place a text list of the post’s comments before Disqus is loaded on the page. Google now indexes Facebook and Disqus comments (and other comment systems like that) but I don’t know about other search engines, so if you consider to be found from other search engines with the comments on your blog, leave this option unchecked; otherwise (meaning you just care about Google and/or you don’t need to be found with the words in the comments of your posts) check this option and disable server side rendering.

Check one of your posts to see how Disqus loads itself over the native comment system. You’re good to go now!

Exporting Existing Comments to Disqus

Below the options we examined just now, there is the “Import / Export” section where we can, you know, import and export our comments:

Screenshot 4: Exporting existing comments to Disqus

The exporting process consists of clicking that “Export” button and waiting for Disqus to finish “importing” your comments into its database:

Screenshot 5: Exporting existing comments to Disqus - step 2

It could take seconds to hours for the process to be completed – my own blog had 20,000 comments when I switched to Disqus and it literally took hours! But while preparing this tutorial, it took 2 seconds to export 2 comments (for my example blog):

Screenshot 6: Exporting existing comments to Disqus - step 3

All right; now we’re done with the plugin – we can just get rid of it now! :)

Deactivate the plugin, if you’re going to use the code in our next step. I prefer to reactivate it once in a while to backup my Disqus comments into my database (by clicking “Sync Comments” at the “Import / Export” section and waiting for several minutes) but if you don’t think you’re ever going to use the plugin again and won’t need the options that are saved in your database, you can also uninstall it with the “Uninstall” button.

Integrating Disqus Into WordPress Without a Plugin

As we discussed earlier, doing stuff without plugins helps us optimize our website – a single query is a single query, right?

Anyways, here are the functions that we’re going to use – like always, add these inside your theme’s functions.php file:

Embedding Disqus Comments

function disqus_embed($disqus_shortname) {
	global $post;
	wp_enqueue_script('disqus_embed','http://'.$disqus_shortname.'.disqus.com/embed.js');
	echo '<div id="disqus_thread"></div>
	<script type="text/javascript">
		var disqus_shortname = "'.$disqus_shortname.'";
		var disqus_title = "'.$post->post_title.'";
		var disqus_url = "'.get_permalink($post->ID).'";
		var disqus_identifier = "'.$disqus_shortname.'-'.$post->ID.'";
	</script>';
}

The function is pretty simple: Use the code <?php disqus_embed('myexampleblog'); ?> anywhere you want in your single.php and page.php files to embed and show Disqus comments for that page. You can search for the comments_template(); function and replace it with our new function, since we’re not going to use the native commenting functions anymore.

Let’s examine the code a little bit:

  1. Load the JS: As you know, we can’t do anything if we don’t load the JS! :)
  2. Place the div to load the comments in: We’re echoing <div id="disqus_thread"></div> because Disqus needs this div with this ID to load the comments in.
  3. JS configuration variables of Disqus: We have to set these variables in order to make the page recognizable for Disqus. We don’t really have to set disqus_title and disqus_url since Disqus can fetch them from the page’s URL and <title> tag but if someone visits your site with an address that contains, say, ...?utm_source=feedburner, the URL will be different from the original and that can cause problems.

Tip: Try to load yourdisqusshortname.disqus.com/embed.js in your browser – you’ll be redirected to Disqus’ CDN. Copy that new link and use it in the wp_enqueue_script function to optimize the code a little further – half a second is half a second, right?

Fetching the Comment Count

function disqus_count($disqus_shortname) {
	wp_enqueue_script('disqus_count','http://'.$disqus_shortname.'.disqus.com/count.js');
	echo '<a href="'. get_permalink() .'#disqus_thread"></a>';
}

We can use the code (<?php disqus_count('myexampleblog'); ?>) anywhere in our theme files as long as it’s in The Loop. Unfortunately Disqus can only count the comments with a link which has #disqus_thread in the end – help me out with your comments if you find a different way to show the comment count.

Tip: You can edit the output text by visiting yourdisqusshortname.disqus.com/admin/settings/appearance/ and changing the “Comment Count Link” and “Reaction Count Link” boxes. You can even use HTML!

Conclusion

Disqus was founded in 2007 and has over 75 million users worldwide. It maybe lacks some configuration features but it’s one of the greatest comment systems out there. This article’s main idea was to show you how to register with Disqus, install it on your WordPress blog, migrate your comments and use several lines of code to show the comments. For a further review of Disqus, you can refer to another article on Wptuts+ and get to know it better.

And as always, you’re more than welcome to share your ideas and code relevant to this topic on your comments!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • GorillaWma

    Nice article, but fix post on front side :)

  • http://laranz.in Lawrence77

    I think you guys miss the more tag. :D

    • http://wp.envato.com/ Japh Thomson
      Staff

      Quite right! Thanks for pointing that out. Fixed it up now.

    • Rock

      Yes, right.

  • http://daniel.bottle-imp.com/ Daniel

    Bookmarking this. I maintain that most people using WordPress should opt for a system like Disqus for its social media integration. I see so many of my friends and associates still have their WordPress installs setup to use the built in comments and have it setup so you have to register to comment. It always feels counter-intuitive and when I point them to Disqus they love it. So thanks for the good write up, will make great reference material.

    • http://pippinsplugins.com Pippin

      Personally, I couldn’t disagree more. I hate the experience of using Disqus for a site’s comments and for leaving comments on a site. Some of it comes from me being a WP purest, but I also strongly dislike how Disqus completely removes comments from the WordPress system. When using Disqus, you can’t use the WP comments interface. And what if you choose to move away from it? Do you comments get sent back into WP? I suspect the answer is no.

      • http://beyn.org/ Barış Ünver
        Author

        Hey Pippin. You can synchronize Disqus comments with your WP comments automatically or manually with the plugin. Also, Disqus’ WP plugin doesn’t remove the native WP comments; you can disable the plugin and continue using WordPress’ default comments system any time you want :).

      • http://pippinsplugins.com Pippin

        That’s good to know. It didn’t used to be that way, so they must have updated it.

    • im

      ok

    • im

      this have very profit.

  • http://www.b2284.com Brian Murray

    Im interested to see how Discuss’ numbers will change now that Jetpack is becoming more and more widely installed and now with jetpack comments (similar to wordpress.com’s new layout) where you can log in via social media networks.

  • Nathan

    I have tried to get Disqus to only work on post with comments disabled but it doesn’t seem to work. Any ideas?

  • Pingback: Spanky Media Provides Exceptional Custom WordPress Development for … | Open Knowledge

  • http://www.leachcreative.com Andrew

    I’ve used Disqus in the past, and I didn’t like it all that much. There was a pretty big increase in load time, and the styling was much more difficult than it needed to be.

  • http://www.creativemanner.com ozgur coruhlu

    Tesekkurler Baris!

  • http://www.matchboxdesigngroup.com Cullen

    Thanks for showing how to set this up without the plugin. It definitely seems cleaner…

    It seems great that you can now sync your comments but can you tie it into the WP user accounts or do they have to be separate accounts?

  • Pingback: Integrating Disqus Into WordPress - Tutsplus

  • Pingback: Weekly WordPress Review » WPCanada

  • Krystal

    What is the difference between Discus and Livefyre? Why is Discus better?

    • http://www.techmansworld.com/ Michael Hazell

      Disqus and Livefyre are two different discussion systems. I personally find Disqus better because it virtually installs on every platform. If not, then of course everyone has access to some JavaScript code. Disqus is also used on many web sites, and holds the majority of third party commenting systems marketshare.

  • Pingback: Quick Tip: Using Jetpack's New Comment System | Wptuts+

  • Pingback: Quick Tip: Using Jetpack’s New Comment System | Wordpress Webdesigner

  • Pingback: Quick Tip: Using Jetpack’s New Comment System - Tutorial Barn

  • Pingback: Quick Tip: Using Jetpack’s New Comment System | Shadowtek Hosting and Design Solutions

  • Pingback: My Stream | Quick Tip: Using Jetpack’s New Comment System | My Stream

  • Pingback: Quick Tip: Using Jetpack’s New Comment System | How to Web

  • Pingback: Как интегрировать Disqus в WordPress | iostream.org.ua

  • Pingback: 6 maneiras fáceis e eficientes de se combater spams em comentários | wpmidia lab

  • http://amirfaizal.com Amir Faizal

    Very interesting! I have a question for using Discus manually without the wp plugin. Once i implement the code such above, do i have the comments database considering it comes with no plugin that has export/import menu.

    • http://www.techmansworld.com/ Michael Hazell

      If you are using WordPress, then using the plugin is really the best thing you can do. Otherwise, you are creating more steps and stress for yourself.

  • http://www.onedirection.net Chris

    We’ve been using Disqus on our site for a while now, and love the new features of the 2012 version, but we are missing out on having our comments indexed by Google.

    I know we can revert back to the older Disqus version and have the comments rendered by WordPress, but then we’d miss out on the community stuff you get in the new version.

    Whats the best approach here?

    Chris.

    • http://www.techmansworld.com/ Michael Hazell

      I think that there is some comment text placed on a site for indexing purposes, and then it gets hidden when the Disqus plugin actually loads.

  • Pingback: Devilの软件巴士,分享你我的软件 » 6种对付WordPress垃圾评论的有效方法

  • mostafamaklad

    I used disqus but it doesn’t let guests to leave comment it makes them register first, how to make it let guests comment

    • http://www.techmansworld.com/ Michael Hazell

      There is a “who can comment” section in the Disqus admin panel. When guest commenting is disabled, it does not display a guest login option.

  • http://drhack.net/ Dr-Hack

    why my trackbacks/pings are not shown any where in reactions in disqus ? .. how to get onto it .. trackbacks are on in disqus aswell as WP
    thanks:)

  • http://noelcohen.webstarts.com/ RisaRichardson

    If you are using WordPress, then using the plug-in is really the best factor you can do. Otherwise, you are developing more actions and pressure for yourself.

    • http://www.webdevelopments.co.in/ Digvijay Singh

      But in wordpress.com, you can not add any external plugin in a blog. Is wordpress.com has own plug-in to integrate Disqus into WordPress blog?

  • Guest
  • Guest
  • Guest

    taghvim

  • http://twitter.com/xYoungBx I ♥ Avril Lavigne!

    mhmm

  • http://www.facebookcorner.com/ Buy facebook fans

    Nice thank you for the image with the code. Such kind of information helps other.

  • lee

    thanks for the article,
    one question, for the tip #1 , what should we do ?

  • Pingback: Every Tutorials | Tutorials about… everything

  • Alan Wu

    Thanks for the post. But I found that the comments are not showing up with the custom code (but they’re showing up with the disqus plugin). Any ideas?

  • http://burtonbates.webstarts.com/ AmeryKinney

    I think that there is some opinion written text placed on a website for listing requirements, and then it gets invisible when the Disqus plug-in actually plenty.

  • http://banklesstimes.com/ John White

    Is there an easy way to show comment counts on the main page in number AND ICON only? I know you can ‘hide text’ but I want to add a comment icon

  • http://www.jokesfb.com/ Nisha

    Its Work Thanks for these code , Its a great help to setup Disqus.

  • http://www.webdevelopments.co.in/ Digvijay Singh

    Hey, is it possible to Integrat Disqus into WordPress blog? This is my blog url : http://wdcompany.wordpress.com/

  • Pingback: Adding Disqus into WooCommerce | Pasar Cinde

  • prakashapkota

    How can i show all comments on the post? just like a Forum? thank you

  • http://www.healthinformationtips.net/ health insurance

    I maintain that most people using WordPress should opt for a system like Disqus for its social media integration.

  • http://vietmuasam.net/ Hoàng Thanh

    how to display same as Also on Wptuts, you can guide Current I

  • Pingback: Disqus en WordPress sin necesidad de plugin | Blog sobre diseño web, trucos para Wordpress, Tecnología, y mucho más.

  • http://twitter.com/ccmanners Caldwell Manners

    I’ve been having issues with Disqus not resizing and being responsive to the size of the window. Anybody have some CSS tips?

  • http://healthbenefitsoff.com/ Manish gupta

    Thanks a lot! I maintain that most people using WordPress should opt for a system like Disqus for its social media integration.

  • Pingback: wordpress对付垃圾评论的六种有效方法 - 萝卜居—萝卜家园网

  • http://twitter.com/joey89924 joey

    you can guide Current I
    HV9910

  • http://raihancheaterblogger.wordpress.com/ Raihan Yudo Saputra

    not work

  • ajkumar25

    The universal code helped me a lot, thanks !!!

  • http://www.incometreatment.com/ Hasan Imam

    hgjsjj

  • http://www.openeshore.com/wordpress-development.htm WordPress Development

    Such a nice tutorial with including full of images and complete information. I am really thankful to you for sharing this amazing information here and helps me a lot. Keep Sharing.

  • Hernan

    I installed Disqus without a plugin in WordPress. I noticed, however, that by doing it this way I cannot longer moderate comments, even if I choose the Moderate all comments option. All comments get approved immediately and show it in my posts.

    If I install the plugin, then the comments are subject to approval before being published, the way it should be. Has anyone else have this issue too?

  • http://twitter.com/alegadpen Ale Gadpen

    Great Tut!! =)

  • http://www.gemmawild.co.uk/ Gemma Wild

    Probably a silly question but the tutorial is unclear as to whether we have to manually set our ‘$disqus_shortname’ or not? I can’t see how it would automatically pick it up but could you clarify if we do and where please? Thanks =)

    • http://www.seojeek.com/ Alex Vallejo

      Yes, the Disqus shortname should be found in your Disqus Settings->General.

      • http://www.gemmawild.co.uk/ Gemma Wild

        Hi Alex, I think you may have missed my point slightly. In the code given above, do we have to change the ‘$disqus_shortname’ variable to whatever our shortname is? For instance, it appears 4 times in the given code so do we change each one, such as “var disqus_shortname = “‘.$disqus_shortname.’”;” to “var disqus_shortname = “‘yourshortname’”;” Thanks.

        • http://www.seojeek.com/ Alex Vallejo

          Well you would just pass the shortname to the function, disqus_embed(YourShortNameHere)

          • http://www.gemmawild.co.uk/ Gemma Wild

            That didn’t work for me.

  • Pingback: WooCommerce Indonesia Edition | Pasar Cinde

  • Pingback: Integrating Disqus Comment System with Woocommerce | My Blog

  • http://www.bytetips.com/ Garnel K

    Great Thanks for the info. Added my blog to disqus. waiting for comments to show up..

  • SergeiNovik

    I have integrated SSO into our wordpress site. In our site, there is a custom user section. The user Details store into a table namely, ‘tbl_user’. while the users register or login into disqus, I want to add disqus user informations into our database table, ‘tbl_user’ . How can I do so? Please Help me. I am new in disqus.

    • Mithun

      I have the same problem. Please, give us a proper solution.

  • Smith J

    I love this service and I use this for last couple of months. I will add this to my blog. Thanks for sharing. custom writing

  • jdangla

    Yes Im having a problem wit this ting

  • Pingback: Best Wordpress Tutorials Which Will Make Your Life Easy - Webkia

  • congpho

    vãi

  • http://kustomdesigner.com/ michael h

    The comment count isnt working for me, everything else is though. Don’t know what is going on.

  • DevilishData

    i already use disqus much better than default wp comments, my question is as today i installed woocommerce for the first time which has a default reviews tab, how would i replace this with disqus comments in the tab replacing the woocommerce reviews option

    • http://www.aboveandbelow.org/ Kyle Harris

      Also looking for the same thing

  • http://www.aboveandbelow.org/ Kyle Harris

    Any one know how to get disqus to replace woocommerce reviews, all tutorials ive found dont work with the new update

  • http://www.magentodevelopments.com/ magento development india

    These recommendations are for self-hosted WordPress platforms systems set ups.
    1. In the staying panel of your WordPress platforms systems management, select Plug-ins > Add New
    2. Search for “Disqus” and get the plug-in provided by “Disqus”.
    3. Select Set up Now > Activate Plugin
    4. Proceed with the on-screen set up recommendations.
    5. In the shortname place, get into your shortname.

  • DailyRushbo

    knkn

  • http://www.innovativeconsulting.co.in/ HaryJames

    Integrating Disqus Into WordPress is really a new way of exploring the applications.This will really helpful in social media services. Thanks for posting this information.

  • http://www.howtofindworkfromhome.com/ Patti Hale

    I have been having fits trying to get the Disqus comments from old website to import into WordPress for over 3 months now. Disqus has not been helpful and slow to even answer my emails! I used the plugin and used the feature to migrate my comments from another website. That didn’t work so after a month or so they sent me a csv file to map the old url to the new urls (they were the same) then load it back up. I was told it would start populating within 24 hours. Not only did it not “populate” now comments are either closed or not showing up on my blog.

  • http://www.facebook.com/sendung.cool.3 Sendung Cool

    i already use disqus a lot better than default wp comments, my question can be as these days i installed woocommerce regarding the first time that uses a default reviews tab, how would i replace this with disqus comments within the whole tab replacing the woocommerce reviews possibility
    http://peluangbisnise.blogspot.com/2013/04/ultrabook-terbaru.html

  • http://www.facebook.com/mesir.kadal.1 Mesir Kadal
  • Marko Ristanovic

    nice one

  • http://www.biztechconsultancy.com/php-development-india.htm php development india

    It’s working greatly for me. Thanks a lot for this awesome help. Keep sharing.

  • http://momymilk.com/ Kenzoo Kha

    wow.. it’s a great article.. i was registered on disqus, but i can’t put on the disqus comment system on my blog.. i’ll try this tips.. thanks .. :)

    HostingPangeran Web Hosting Murah Berkualitas

  • http://www.innovativeconsulting.co.in/ HaryJames

    Really a great way of presenting how to integrate Disqus into word press.No doubt, this post is really helpful.