0

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';

To:

$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?

Edit

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);
5
  • What is the relevant code in your template file(s)? Nov 20, 2013 at 18:35
  • Just looking now. Nov 20, 2013 at 18:37
  • I've likely missed something, but what file would you expect to find it in? Is it a standard location? Nov 20, 2013 at 18:44
  • It's entirely Theme-dependent. It'll be somewhere in the Loop, though. Nov 20, 2013 at 18:45
  • I can't seem to find anything... Nov 20, 2013 at 19:40

1 Answer 1

0

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 );
3
  • I tried this in the themes functions.php file with no luck. Should that have worked? Nov 20, 2013 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? Nov 20, 2013 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 Nov 20, 2013 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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