Using WordPress ‘edit_comment_link()’ PHP function

The edit_comment_link() WordPress PHP function displays the edit comment link with formatting.

Usage

Here’s a simple usage example:

edit_comment_link( 'Edit Your Comment', '<div>', '</div>' );

In this example, the function will display the edit comment link, with the text saying “Edit Your Comment”, enclosed within a ‘div’ tag.

Parameters

  • $text (string, optional): This is the anchor text. If not provided, the default text is ‘Edit This’.
  • $before (string, optional): This is the content to be displayed before the edit link. By default, this is an empty string (”).
  • $after (string, optional): This is the content to be displayed after the edit link. By default, this is an empty string (”).

More information

See WordPress Developer Resources: edit_comment_link()

This function is part of the core WordPress code, and is not deprecated as of the last known update.

Examples

edit_comment_link();

In this case, the edit comment link will be displayed with the default text ‘Edit This’.

Changing the anchor text

edit_comment_link( 'Modify Comment' );

Here, the edit comment link will be displayed with the text ‘Modify Comment’ instead of the default ‘Edit This’.

edit_comment_link( 'Modify Comment', 'Please ', ' this comment.' );

The edit comment link will now display as “Please Modify Comment this comment.”

edit_comment_link( 'Modify Comment', '<strong>', '</strong>' );

This will make the ‘Modify Comment’ text bold.

edit_comment_link( 'Modify Comment', '<div class="edit-link"><em>', '</em></div>' );

This will display the ‘Modify Comment’ text in italics, enclosed within a div tag with the class “edit-link”.