get_comments_link()
Retrieves the link to the current post comments.
Uses: get_permalink()
Used By: comments_link()
Hooks from the function
Return
String
. The link to the comments.
Usage
get_comments_link( $post );
- $post(int|WP_Post)
- Post ID or WP_Post object.
Default: global $post
Examples
#1 Get link to the comment
Suppose the function is called on a page with a URL: http://example.com/page
, then:
// if the post has no comments: echo get_comments_link(); //> http://example.com/page#respond // if the post has comments: echo get_comments_link(); //> http://example.com/page#comments
Changelog
Since 1.5.0 | Introduced. |
get_comments_link() get comments link code WP 6.7.2
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 ); }