edit_comment_link()WP 1.0.0

Displays the edit comment link with formatting.

Hooks from the function

Return

null. Nothing (null).

Usage

edit_comment_link( $text, $before, $after );
$text(string)
Anchor text. If null. Default null.
Default: 'Edit This'
$before(string)
Display before edit link.
Default: ''
$after(string)
Display after edit link.
Default: ''

Examples

0

#1 Display a link to edit a comment

Use this code in the comments loop (comments.php file):

<?php edit_comment_link(); ?>
0

#2 Change the text of the link and put the link in the html tag <p>:

<?php edit_comment_link( 'edit comment', '<p>', '</p>' ); ?>

Changelog

Since 1.0.0 Introduced.

edit_comment_link() code WP 6.5.2

function edit_comment_link( $text = null, $before = '', $after = '' ) {
	$comment = get_comment();

	if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
		return;
	}

	if ( null === $text ) {
		$text = __( 'Edit This' );
	}

	$link = '<a class="comment-edit-link" href="' . esc_url( get_edit_comment_link( $comment ) ) . '">' . $text . '</a>';

	/**
	 * Filters the comment edit link anchor tag.
	 *
	 * @since 2.3.0
	 *
	 * @param string $link       Anchor tag for the edit link.
	 * @param string $comment_id Comment ID as a numeric string.
	 * @param string $text       Anchor text.
	 */
	echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID, $text ) . $after;
}