edit_comment_link()WP 1.0.0

Outputs a link (HTML tag A) for editing the current comment in the loop, if the user has permission to do so.

This template tag should be used inside the Comments Loop.

Hooks from the function

Returns

null. Outputs the HTML code for the link.

Usage

<?php edit_comment_link( $link, $before, $after ); ?>
$link(string)
Text of the link.
Default: null — __('Edit This')
$before(string)
Text before the link. HTML code can be used.
Default: ''
$after(string)
Text after the link.
Default: ''

Examples

1

#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.9

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