WordPress.org

Ready to get started?Download WordPress

Forums

Simple comment link fix (1 post)

  1. epiloguetravis
    Member
    Posted 9 years ago #

    This has probably been done before, but I couldn't find it.. So here it goes:

    Something that had bugged me about wordpress, was that when you click the comments link (<?php comments_link(); ?>), it always took you to yourpage/#comments which if there were no comments yet, just took you to the permalink. There wasn't a method I could find to create a "leave comment" link that would always drop down to the comment box, so I came up with one.

    What I did was modify comment-functions.php in the wp-includes folder. If you open that up, and scroll down a little ways, you'll find

    function get_comments_link() {
    return get_permalink() . '#comments';
    }

    function get_comment_link() {
    global $comment;
    return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
    }

    function comments_link( $file = '', $echo = true ) {
    echo get_comments_link();
    }

    To create a "leave comments" link, I copied that entire thing, and put it below the original, and then changed comments_link to comments_link_post, (all of them in the copy) as well as changing the line return get_permalink() . '#comments'; to return get_permalink() . '#comment'; So that with the new function, it will return yourpage/#comment and take you directly to the leave comment box.

    The last step is to put the function in your template where you want the "leave comments" link to be with the simple <code><a href="<?php comments_link_post(); ?>">Leave a Comment</a>

    You can see the result at http://www.travislankow.com

Topic Closed

This topic has been closed to new replies.

About this Topic