get_comments_link

The timeline below displays how wordpress function get_comments_link has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Retrieves the link to the current post comments.
 *
 * @since 1.5.0
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string The link to the comments.
 */
function get_comments_link($post = 0)
{
    $hash = get_comments_number($post) ? '#comments' : '#respond';
    $comments_link = get_permalink($post) . $hash;
    /**
     * Filters the returned post comments permalink.
     *
     * @since 3.6.0
     *
     * @param string      $comments_link Post comments permalink with '#comments' appended.
     * @param int|WP_Post $post          Post ID or WP_Post object.
     */
    return apply_filters('get_comments_link', $comments_link, $post);
}

WordPress Version: 4.6

/**
 * Retrieves the link to the current post comments.
 *
 * @since 1.5.0
 *
 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
 * @return string The link to the comments.
 */
function get_comments_link($post_id = 0)
{
    $hash = get_comments_number($post_id) ? '#comments' : '#respond';
    $comments_link = get_permalink($post_id) . $hash;
    /**
     * Filters the returned post comments permalink.
     *
     * @since 3.6.0
     *
     * @param string      $comments_link Post comments permalink with '#comments' appended.
     * @param int|WP_Post $post_id       Post ID or WP_Post object.
     */
    return apply_filters('get_comments_link', $comments_link, $post_id);
}

WordPress Version: 4.4

/**
 * Retrieves the link to the current post comments.
 *
 * @since 1.5.0
 *
 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
 * @return string The link to the comments.
 */
function get_comments_link($post_id = 0)
{
    $hash = get_comments_number($post_id) ? '#comments' : '#respond';
    $comments_link = get_permalink($post_id) . $hash;
    /**
     * Filter the returned post comments permalink.
     *
     * @since 3.6.0
     *
     * @param string      $comments_link Post comments permalink with '#comments' appended.
     * @param int|WP_Post $post_id       Post ID or WP_Post object.
     */
    return apply_filters('get_comments_link', $comments_link, $post_id);
}

WordPress Version: 4.0

/**
 * Retrieve the link to the current post comments.
 *
 * @since 1.5.0
 *
 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
 * @return string The link to the comments.
 */
function get_comments_link($post_id = 0)
{
    $comments_link = get_permalink($post_id) . '#comments';
    /**
     * Filter the returned post comments permalink.
     *
     * @since 3.6.0
     *
     * @param string      $comments_link Post comments permalink with '#comments' appended.
     * @param int|WP_Post $post_id       Post ID or WP_Post object.
     */
    return apply_filters('get_comments_link', $comments_link, $post_id);
}

WordPress Version: 3.9

/**
 * Retrieve the link to the current post comments.
 *
 * @since 1.5.0
 *
 * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
 * @return string The link to the comments.
 */
function get_comments_link($post_id = 0)
{
    $comments_link = get_permalink($post_id) . '#comments';
    /**
     * Filter the returned post comments permalink.
     *
     * @since 3.6.0
     *
     * @param string      $comments_link Post comments permalink with '#comments' appended.
     * @param int|WP_Post $post_id       Post ID or WP_Post object.
     */
    return apply_filters('get_comments_link', $comments_link, $post_id);
}

WordPress Version: 3.7

/**
 * Retrieve the link to the current post comments.
 *
 * @since 1.5.0
 *
 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default current post.
 * @return string The link to the comments.
 */
function get_comments_link($post_id = 0)
{
    $comments_link = get_permalink($post_id) . '#comments';
    /**
     * Filter the returned post comments permalink.
     *
     * @since
     *
     * @param string      $comments_link The post comments permalink with '#comments' appended.
     * @param int|WP_Post $post_id       The post ID or WP_Post object.
     */
    return apply_filters('get_comments_link', $comments_link, $post_id);
}