get_comments_link() WordPress Function

The get_comments_link() function retrieves the URL for the comments page of the current post. This function is useful for creating a link to the comments page from within the post content.

get_comments_link( int|WP_Post $post_id ) #

Retrieves the link to the current post comments.


Parameters

$post_id

(int|WP_Post)(Optional) Post ID or WP_Post object. Default is global $post.


Top ↑

Return

(string) The link to the comments.


Top ↑

Source

File: wp-includes/comment-template.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More