get_comments_link

Retrieves the link to the current post comments.

Description

(string) get_comments_link( (int) $post_id = 0 ); 

Returns (string)

The link to the comments.

Parameters (1)

0. $post_id — Optional. (int)
Post ID or WP_Post object. Default is global $post.

Usage

  1. if ( !function_exists( 'get_comments_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment-template.php'; 
  3.  
  4. // Optional. Post ID or WP_Post object. Default is global $post. 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_comments_link($post_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment-template.php  
  1. function get_comments_link( $post_id = 0 ) { 
  2. $hash = get_comments_number( $post_id ) ? '#comments' : '#respond'; 
  3. $comments_link = get_permalink( $post_id ) . $hash; 
  4.  
  5. /** 
  6. * Filters the returned post comments permalink. 
  7. * @since 3.6.0 
  8. * @param string $comments_link Post comments permalink with '#comments' appended. 
  9. * @param int|WP_Post $post_id Post ID or WP_Post object. 
  10. */ 
  11. return apply_filters( 'get_comments_link', $comments_link, $post_id );