comment_link()WP 1.5.0

Outputs the comment link (URL).

Used in the comments loop or you can specify the ID of the comment whose link needs to be output.

Before outputting, the link is processed by esc_url(), i.e., a safe link is returned.

1 time — 0.053325 sec (extremely slow) | 50000 times — 9.37 sec (fast)
Hooks from the function

Returns

null. Nothing. Outputs the result on the screen.

Usage

comment_link( $comment );
$comment(int/WP_Comment)
ID or object of the comment. By default, the global object where the current comment in the loop is stored.
Default: null (current comment in the loop)

Examples

0

#1 Output a link to the current comment in the loop

Create an anchored permalink to a single comment.

<a href="<?php comment_link() ?>">Link to this comment</a>

The code shown above will result (depending on your permalink settings) in something like this:

<a href="http://example.com//example-post/comment-page-2/#comment-3">Link to this comment</a>

Changelog

Since 1.5.0 Introduced.
Since 4.4.0 Introduced the $comment argument.

comment_link() code WP 6.9

function comment_link( $comment = null ) {
	/**
	 * Filters the current comment's permalink.
	 *
	 * @since 3.6.0
	 *
	 * @see get_comment_link()
	 *
	 * @param string $comment_permalink The current comment permalink.
	 */
	echo esc_url( apply_filters( 'comment_link', get_comment_link( $comment ) ) );
}