The edit_comment_link WordPress PHP filter allows you to modify the comment edit link anchor tag.
Usage
add_filter('edit_comment_link', 'your_custom_function', 10, 3); function your_custom_function($link, $comment_id, $text) { // your custom code here return $link; }
Parameters
$link
(string): The anchor tag for the edit link.$comment_id
(string): The comment ID as a numeric string.$text
(string): The anchor text.
More information
See WordPress Developer Resources: edit_comment_link
Examples
Change the edit comment link text
Modify the anchor text for the comment edit link.
add_filter('edit_comment_link', 'change_edit_comment_link_text', 10, 3); function change_edit_comment_link_text($link, $comment_id, $text) { $text = 'Edit this comment'; $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment_id ) . '">' . $text . '</a>'; return $link; }
Add a custom class to the edit comment link
Add a custom CSS class to the edit comment link anchor tag.
add_filter('edit_comment_link', 'add_custom_class_edit_comment_link', 10, 3); function add_custom_class_edit_comment_link($link, $comment_id, $text) { $link = '<a class="comment-edit-link custom-class" href="' . get_edit_comment_link( $comment_id ) . '">' . $text . '</a>'; return $link; }
Add an icon to the edit comment link
Add a font-awesome icon to the edit comment link.
add_filter('edit_comment_link', 'add_icon_edit_comment_link', 10, 3); function add_icon_edit_comment_link($link, $comment_id, $text) { $icon = '<i class="fas fa-edit"></i> '; $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment_id ) . '">' . $icon . $text . '</a>'; return $link; }
Change the edit comment link URL
Change the URL of the edit comment link to a custom URL.
add_filter('edit_comment_link', 'change_edit_comment_link_url', 10, 3); function change_edit_comment_link_url($link, $comment_id, $text) { $custom_url = 'https://example.com/custom-url/'; $link = '<a class="comment-edit-link" href="' . $custom_url . '">' . $text . '</a>'; return $link; }