I have made some custom changes to the file wp-includes\comment-template.php. These changes are periodically lost and I assume it's related to updates for WordPress and the file is modified/re-written.

I have changed:

$comments_link = get_permalink( $post_id ) . '#comments';


$comments_link = get_permalink( $post_id ) . '#disqus_thread';

Is there a way I can persist these changes so they are not lost? Or perhaps there is a better way to make these changes?


I've tried this code in my themes functions.php file.

function custom_comments_link($comments_link, $post_id){
    return get_permalink($post_id) . '#disqus_thread';
add_filter('get_comments_link', 'custom_comments_link', 10, 2);
  • What is the relevant code in your template file(s)? – Chip Bennett Nov 20 '13 at 18:35
  • Just looking now. – Scott Helme Nov 20 '13 at 18:37
  • I've likely missed something, but what file would you expect to find it in? Is it a standard location? – Scott Helme Nov 20 '13 at 18:44
  • It's entirely Theme-dependent. It'll be somewhere in the Loop, though. – Chip Bennett Nov 20 '13 at 18:45
  • I can't seem to find anything... – Scott Helme Nov 20 '13 at 19:40

There's a filter for that: get_comments_link. Refer to source:

return apply_filters( 'get_comments_link', $comments_link, $post_id );

In an appropriate place (such as a site functionality Plugin), just add a filter via callback:

function wpse123906_filter_comments_link( $comments_link, $post_id ) {
    // Return your custom link
    return get_permalink( $post_id ) . '#disqus_thread';
add_filter( 'get_comments_link', 'wpse123906_filter_comments_link', 10, 2 );
| improve this answer | |
  • I tried this in the themes functions.php file with no luck. Should that have worked? – Scott Helme Nov 20 '13 at 18:27
  • Yes, it should have. Can you edit your question with more details, including what you tried (both the filter, and the template code that outputs the comments link), and what didn't happen as expected/happened unexpectedly? – Chip Bennett Nov 20 '13 at 18:33
  • You can see that on the main page, comment links are #disqus_thread, then clicking through to a post it is #respond scotthelme.co.uk – Scott Helme Nov 20 '13 at 18:34

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.