I have recently installed Disqus on my blog and have a problem with the link in the comment count.

On the main page here all the comments counts for each post link to the appropriate URL for the post with #disqus_thread appended to take the user to the comment section at the bottom.

If you navigate to the post by clicking the title like here the link on the comment count changes to #respond which doesn't work.

How/where do I edit this value to be #disqus_thread so it takes the user to the comments below as it should?


Filter get_comments_link to change the URL. You get two arguments: the link and the post ID.

add_filter( 'get_comments_link', function( $link, $post_id ) 
    return get_permalink( $post_id ) . '#disqus_thread';
}, 10, 2 );
  • Please excuse my lack of experience in WP but where do I need to add the filter? Oct 13 '13 at 13:36
  • @ScottHelme In a plugin or your theme’s functions.php. See Where do I put the code snippets?
    – fuxia
    Oct 13 '13 at 13:47
  • I get a fatal exception when creating my own plugin, it will not activate. Oct 13 '13 at 13:57
  • @ScottHelme Sorry, had a typo in my code. :) Fixed now.
    – fuxia
    Oct 13 '13 at 14:00
  • 1
    @ScottHelme Your PHP version is very outdated. Upgrade to 5.5 or at least 5.4. Your version 5.2 is insecure, slow, and missing features.
    – fuxia
    Oct 13 '13 at 14:16

I found the section of code I needed to modify in wp-includes\comment-template.php:

I changed this:

return apply_filters( 'get_comments_link', get_permalink( $post_id ) . '#comments', $post_id );

To this:

return apply_filters( 'get_comments_link', get_permalink( $post_id ) . '#disqus_thread', $post_id );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.