comments_link()
Display the link to the current post comments.
Uses: get_comments_link()
Used By: comments_popup_link()
1 time — 0.001856 sec (very slow) | 50000 times — 3.18 sec (fast) | PHP 7.1.5, WP 4.8.2
No Hooks.
Return
null
. Nothing (null).
Usage
comments_link( $deprecated, $deprecated_2 );
- $deprecated(string)
- Not Used.
Default: '' - $deprecated_2(string)
- Not Used.
Default: ''
Examples
#1 Demo
comments_link();
It displays on the screen:
- if the post has no comments:
http://example.com/postname#respond
- if the post has comments:
http://example.com/postname#comments
#2 Display a link to the comment form of the current post in the WordPress Loop:
<a href="<?php comments_link(); ?>">Leave a comment</a>
If you apply this code to a category page, for example, you will get a "leave a comment" link for each post, which will take the user straight to the comment form on the post page.
Changelog
Since 0.71 | Introduced. |
comments_link() comments link code WP 6.6.1
function comments_link( $deprecated = '', $deprecated_2 = '' ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '0.72' ); } if ( ! empty( $deprecated_2 ) ) { _deprecated_argument( __FUNCTION__, '1.3.0' ); } echo esc_url( get_comments_link() ); }