WordPress edit_comment_link() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints a 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.

WordPress
<?php edit_comment_link( 'Edit' ); ?>
CallWhat 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
WordPress
edit_comment_link( string $text = null, string $before = '', string $after = '' ): void

Parameters

ParameterDescription
$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 ValueDescription
voidNothing 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.

Example 1 — Show an edit link under a comment

The simplest use. Add one line where each comment is printed.

WordPress
<?php
// Inside your comment template
comment_text();
edit_comment_link( 'Edit' );

How It Works

  1. comment_text() prints the comment.
  2. edit_comment_link() adds an Edit link.
  3. 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.

WordPress
<?php
edit_comment_link( 'Edit comment', '<span class="edit-link">', '</span>' );

How It Works

  1. The first value is the link text.
  2. The other two values wrap the link.
  3. 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.

WordPress
<?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>';
}

How It Works

  1. ctf_comment() is called once for every comment.
  2. Inside it, the edit link works on that comment.
  3. The | before the link prints only when the link prints.

Frequently Asked Questions

It prints a link to the admin screen where the current comment can be edited. Only users who can edit that comment see it.
You need to be logged in as a user who can edit comments, and the function must run inside the comment loop.
No, it prints it. To get only the URL, use get_edit_comment_link().
WordPress adds the class comment-edit-link, so you can style it in your theme.
Yes. Pass your text as the first argument, for example edit_comment_link( 'Change' ).

Next: edit_post_link()

Print an Edit link for a post or page when the current user can edit it.

edit_post_link() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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