The get_edit_comment_link() WordPress PHP function retrieves the edit comment link.
Usage
$edit_comment_link = get_edit_comment_link( $comment_id );
Parameters
- $comment_id (int|WP_Comment, Optional) – Comment ID or WP_Comment object.
More information
See WordPress Developer Resources: get_edit_comment_link
Examples
Get edit comment link using comment ID
This example retrieves the edit comment link using a comment ID.
$comment_id = 15; $edit_comment_link = get_edit_comment_link( $comment_id ); echo $edit_comment_link;
Get edit comment link using WP_Comment object
This example retrieves the edit comment link using a WP_Comment object.
$comment = get_comment( 15 ); $edit_comment_link = get_edit_comment_link( $comment ); echo $edit_comment_link;
Display edit comment link with text
This example displays the edit comment link with the text “Edit this comment”.
$comment_id = 15; $edit_comment_link = get_edit_comment_link( $comment_id ); echo '<a href="' . esc_url( $edit_comment_link ) . '">Edit this comment</a>';
Display edit comment link in a list of comments
This example shows how to display the edit comment link for each comment in a list of comments.
$comments = get_comments(); foreach ( $comments as $comment ) { $edit_comment_link = get_edit_comment_link( $comment ); echo '<a href="' . esc_url( $edit_comment_link ) . '">Edit comment #' . $comment->comment_ID . '</a><br>'; }
Conditionally display edit comment link for logged-in users
This example displays the edit comment link only if the user is logged in and has the ‘edit_comment’ capability.
$comment_id = 15; if ( current_user_can( 'edit_comment', $comment_id ) ) { $edit_comment_link = get_edit_comment_link( $comment_id ); echo '<a href="' . esc_url( $edit_comment_link ) . '">Edit this comment</a>'; }