Quick Code Fix: Disqus ‘Same Comment’ Problem in WordPress

I found a quick fix for a comment repeating problem I was seeing on my blog with disqus. I’m not a PHP or wordpress hacker (normally) so take this with a grain of salt.

I had recently updated my blog’s theme to a new, major-version-release of Thesis. After the update all of my posts began showing the comments from the same post. I tried uninstalling and reinstalling the disqus plugin but that didn’t work.

A little googling and I found a few posts on the subject:

So now I had a hint as to the problem but I didn’t find a clear fix on the googs.

Looking at the generated HTML for each post I found that the disqus_identifier was being set to a single space ‘ ‘.

Spelunking around in the plugin code, first I found where the javascript was being created in comments.php.

<script type="text/javascript">
/* <![CDATA[ */
    var disqus_url = '<?php echo get_permalink(); ?>';
    var disqus_identifier = '<?php echo dsq_identifier_for_post($post); ?>';
    var disqus_container_id = 'disqus_thread';
    var disqus_domain = '<?php echo DISQUS_DOMAIN; ?>';

Following that function I found defined in disqus.php:

function dsq_identifier_for_post($post) {
    return $post->ID . ' ' . $post->guid;

So it looked like the $post global wasn’t available or being set.

This made me believe that the structure of the new version 2.0 Thesis templates has somehow resulted in the disqus plugin code not being able to access the $post global variable. I changed the function to use the get_the_ID() and get_the_guid() functions and now all seems to be working again.

function dsq_identifier_for_post($post) {
    return get_the_ID() . ' ' . get_the_guid();

As far as I can tell from the wordpress docs, those functions should, in theory, work in the same scope as the $post global so I’m not sure why the functions work but the global doesn’t (and I stopped poking around wordpress at this point since it started working, nothing like being a monkey in the control room of a nuclear reactor :) ).

Thought this might help someone out there that hits this specific problem.

Comments on this entry are closed.

  • robin hood

    This is really a
    remarkable topic close to my heart thanks. Keep up the good working!
    remington electric shavers

  • Melvin Gregor

    Hi to everybody,
    it’s really good for me to come on this site, it gives obliging Information.
    home security

  • mark bill

    Hi Dear,
    I truly visit this blog site daily, and I definitely find high-quality
    knowledge from here.
    term life insurance rate

  • Albert einstien

    website! I really love it!! Thanks for sharing such latest thing with us.
    build business credit

  • http://mikepk.com mikepk


  • felyhely

    Hey very nice
    blog!! Man you have done the Amazing efforts to make this blog… I will
    surely bookmark your blog.

    whole life insurance rate

  • felyhely

    Hey buddy, you have
    done the fantastic job, your post is genuinely amazing.
    of Ra deluxe

  • Dianne Hicks

    I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.
    see us: get more followers on twitter

  • felyhely

    Really thought
    provoking post! Quite interesting things and have enjoyed immeasurably.
    family insurance miami lakes florida

  • felyhely

    This is outstanding
    information and the best opportunity for the people who want to learn the
    great knowledge.
    vine vera skin care

  • felyhely

    I was in quest of
    various topics that are enough well-liked and lastly got your blog, it has
    outstanding topics with immense popularity.
    vine vera