Home WordPress Links Functions edit_comment_link() Definition In WordPress, edit_comment_link() prints an Edit link for the current comment. It opens the comment in the admin area.
Use it inside the comments loop of your theme, for example in a comment callback. The link shows only to users who are allowed to edit that comment, such as administrators.
Syntax Call it once for each comment you display.
<?php edit_comment_link( 'Edit' ); ?> Call What it does edit_comment_link()Print the link with the default text. edit_comment_link( 'Edit comment' )Print the link with your own text. edit_comment_link( 'Edit', '<span class="edit">', '</span>' )Wrap the link in your own HTML.
It works on the current comment in the loop. It prints the link, so you do not need echo.
Full declaration edit_comment_link( string $text = null, string $before = '', string $after = '' ): void Parameters Parameter Description $textstring. The link text. If empty, WordPress uses its default text (Edit This). $beforestring. HTML printed before the link. Default is an empty string. $afterstring. HTML printed after the link. Default is an empty string.
Return Value Return Value Description void Nothing is returned. The link is printed only when the user can edit the comment.
WordPress Examples Three short examples. Each one shows the code and what it prints or does.
1. Show an edit link under a comment 2. Wrap the link in a span 3. Use it in a comment callback Example 1 — Show an edit link under a comment The simplest use. Add one line where each comment is printed.
<?php
// Inside your comment template
comment_text();
edit_comment_link( 'Edit' ); <p>Great tutorial, thanks!</p>
<a class="comment-edit-link" href="https://example.com/wp-admin/comment.php?action=editcomment&c=15">Edit</a> How It Works comment_text() prints the comment.edit_comment_link() adds an Edit link.Only a logged-in admin or editor sees that link. Example 2 — Wrap the link in a span Use $before and $after to add markup around the link.
<?php
edit_comment_link( 'Edit comment', '<span class="edit-link">', '</span>' ); <span class="edit-link"><a class="comment-edit-link" href="https://example.com/wp-admin/comment.php?action=editcomment&c=15">Edit comment</a></span> How It Works The first value is the link text. The other two values wrap the link. When the user cannot edit, the span is not printed. Example 3 — Use it in a comment callback A theme can print comments with its own function. Call the edit link inside it.
<?php
function ctf_comment( $comment, $args, $depth ) {
echo '<li id="comment-' . get_comment_ID() . '">';
echo '<strong>' . get_comment_author() . '</strong>';
comment_text();
edit_comment_link( 'Edit', ' | ' );
echo '</li>';
} <li id="comment-15"><strong>Sam</strong><p>Great tutorial, thanks!</p> | <a class="comment-edit-link" href="https://example.com/wp-admin/comment.php?action=editcomment&c=15">Edit</a></li> How It Works ctf_comment() is called once for every comment.Inside it, the edit link works on that comment. The | before the link prints only when the link prints. Frequently Asked Questions What does edit_comment_link() do? It prints a link to the admin screen where the current comment can be edited. Only users who can edit that comment see it.
Why can I not see the link? You need to be logged in as a user who can edit comments, and the function must run inside the comment loop.
Does it return the link? No, it prints it. To get only the URL, use get_edit_comment_link().
What CSS class does the link have? WordPress adds the class comment-edit-link, so you can style it in your theme.
Can I change the link text? Yes. Pass your text as the first argument, for example edit_comment_link( 'Change' ).
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion