Using WordPress ‘comment_row_actions’ PHP filter

The comment_row_actions WordPress PHP filter allows you to modify the action links displayed for each comment in the ‘Recent Comments’ dashboard widget.

Usage

add_filter('comment_row_actions', 'your_custom_function', 10, 2);
function your_custom_function($actions, $comment) {
  // your custom code here
  return $actions;
}

Parameters

  • $actions (string[]): An array of comment actions. Default actions include: ‘Approve’, ‘Unapprove’, ‘Edit’, ‘Reply’, ‘Spam’, ‘Delete’, and ‘Trash’.
  • $comment (WP_Comment): The comment object.

More information

See WordPress Developer Resources: comment_row_actions

Examples

Add a custom link to the comment actions in the ‘Recent Comments’ dashboard widget.

add_filter('comment_row_actions', 'add_custom_comment_link', 10, 2);
function add_custom_comment_link($actions, $comment) {
  $actions['custom_link'] = '<a href="https://example.com?comment_id=' . $comment->comment_ID . '">Custom Link</a>';
  return $actions;
}

Remove the ‘Spam’ action

Remove the ‘Spam’ action from the comment actions in the ‘Recent Comments’ dashboard widget.

add_filter('comment_row_actions', 'remove_spam_action', 10, 2);
function remove_spam_action($actions, $comment) {
  unset($actions['spam']);
  return $actions;
}

Change the ‘Edit’ link text to ‘Modify’ in the comment actions in the ‘Recent Comments’ dashboard widget.

add_filter('comment_row_actions', 'change_edit_text', 10, 2);
function change_edit_text($actions, $comment) {
  $actions['edit'] = str_replace('Edit', 'Modify', $actions['edit']);
  return $actions;
}

Add a custom action based on user role

Add a custom action link for comments by users with the ‘author’ role in the ‘Recent Comments’ dashboard widget.

add_filter('comment_row_actions', 'add_author_custom_action', 10, 2);
function add_author_custom_action($actions, $comment) {
  $user = get_userdata($comment->user_id);
  if (in_array('author', $user->roles)) {
    $actions['author_custom_action'] = '<a href="https://example.com?author_id=' . $user->ID . '">Author Custom Action</a>';
  }
  return $actions;
}

Reverse the order of the comment action links in the ‘Recent Comments’ dashboard widget.

add_filter('comment_row_actions', 'reverse_comment_actions', 10, 2);
function reverse_comment_actions($actions, $comment) {
  return array_reverse($actions, true);
}