comments_link()WP 0.71

Display the link to the current post comments.

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

0

#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
0

#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() code WP 6.4.3

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