Custom disqus_identifier not properly changing default value

I have several pages that are all part of the same topic, and I would like them to use the same comment thread on Disqus. I am using the following code to pull the custom identifier from a custom field:

<?php
    //Attempt to get identifier
    $disqus = get_post_meta($post->ID, 'disqusid', true);
    //if isset & not blank else use $post->ID
    $disqus = (!empty($disqus)) ? $disqus : $post->ID;
?>
<script type="text/javascript">
    var disqus_identifier = '<?=$disqus?>';
</script>

The code is displaying the value from the custom field correctly, however, the Disqus plugin is still using the page ID as the identifier when I inspect the page code. Meaning each page still uses its own comment thread.

Read More

I have tried placing the code in several different places: just before the comments_template(); code, in header.php in various places (before/after wp_head), and in footer.php in various places (before/after wp_footer).

Everything I’ve read makes it sound as simple as adding the identifier code before the embed.js call for Disqus. I feel like I may be missing something special that needs to be done. Is it possible something else is interfering with it? Everything else is working as expected.

Disqus WordPress Plugin: http://wordpress.org/extend/plugins/disqus-comment-system/

The site I’m working on isn’t live until this issue is fixed, but I can set it live if viewing the whole site code will help.

Related posts

Leave a Reply

1 comment

  1. I had to get some band reviews that were already in Disqus from my old site into my new WordPress band site. I only wanted the reviews on our home page so here’s what I did…

    I looked at the code on my old site and grabbed the disqus_identifier value from there.

    I defined and added a custom field named dsq_identifier to my custom page template and gave it the disqus_identifier value from my old site.

    I’m new to WordPress and PHP and I’m sure this is a bad idea, but I needed to get this done, so…

    I edited the Disqus plugin’s comment.php by adding this code after all the var initialization:

    <?php if ( get_post_meta($post->ID, 'dsq_thread_id', true) ) : ?>
      disqus_identifier = '<?php echo get_post_meta($post->ID, 'dsq_identifier', true); ?>';
    <?php endif; ?>
    

    Since I only want to display the review comments on our home page which has the custom field named dsq_identifier, I modified my custom template (which used by several pages). Here’s that code:

    <?php if ( get_post_meta($post->ID, 'dsq_identifier', true) ) : ?>
      <?php comments_template(); ?> 
    <?php endif; ?>
    

    BAAAMMM! Worked the first time.

    If you have any ideas about how to get this to work without changing the Disqus plugin code base, that would rock. I need to take a step back and really think this over after the new site is released in a couple of days.