WordPress at a glance

get_comments_link() WP 1.0

Retrieves the link to the current post comments.

Works based on: get_permalink()
Basis of: comments_link()
Hooks from the function

String. The link to the comments.


get_comments_link( $post_id );
Post ID or WP_Post object.
Default: global $post


Since 1.5.0 Introduced.

Code of get_comments_link() WP 5.7.2

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

From tag: Comments

More from tag: Link (URL)

More from category: Comments

No comments
    Log In