WP – Edit default comment-link for Disqus comments


The fix for the default WordPress comments_popup_link() function is pretty simple. The fix allows to link the comments baloon placed above your post to the Disqus comments at the bottom of your article. This page is a live demo so you can see how it works (not in the mobile version). Here’s the fix:

STEP 1

Open the php page in which the native wordpress function is placed. (The function is placed inside the loop, and can be usually found in single.php or in content.php).
The native function is , and it looks like this:

1
2
3
4
5
<?php if ( comments_open() ) : ?>
        <div class="comments-link">
            <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
        </div>
<?php endif; ?>

STEP 2

Replace the native function with the following:

1
2
3
4
5
<?php if ( comments_open() ) : ?>
    <div class="comments-link">
        <a href="#disqus_thread"><?php comments_number( __( '<span>0</span>  REPLY', 'twentytwelve' ), __( '<span>1</span> REPLIES', 'twentytwelve' ), __( '<span>%</span> REPLIES', 'twentytwelve' ) ); ?></a>
    </div>
<?php endif;  ?>

Note that the href should link to the Disqus div #ID. So check twice if your div id name is #disqus_thread. Otherwise change it to whatever is called. (eg. #divname).
Also, you can change the elements inside the comments_number as you like. I placed some span here and there according to my css rules.

That’s it. Happy coding!

About Disqus

Since the introduction of social networks, the native WordPress comments system is replaced most of the time by all sort of social comments plugins. Disqus comments is probably the best choice.

“Disqus comments plugin” is automatically placed inside the WordPress template, once installed. So, you don’t need to code to add it.
Also, if you imported your WordPress comments into Disqus, it automatically merge the comments numbering within the wordpress function comments_number().