Using WordPress ‘comment_status_links’ PHP filter

The comment_status_links WordPress PHP filter allows you to modify the comment status links displayed in the admin area. These links include ‘All’, ‘Mine’, ‘Pending’, ‘Approved’, ‘Spam’, and ‘Trash’.

Table of contents

Usage

add_filter('comment_status_links', 'your_custom_function');
function your_custom_function($status_links) {
  // your custom code here
  return $status_links;
}

Parameters

  • $status_links (string[]): An associative array of fully-formed comment status links. Includes ‘All’, ‘Mine’, ‘Pending’, ‘Approved’, ‘Spam’, and ‘Trash’.

More information

See WordPress Developer Resources: comment_status_links

Examples

Remove the ‘Mine’ link from the comment status links.

add_filter('comment_status_links', 'remove_mine_link');
function remove_mine_link($status_links) {
  unset($status_links['mine']);
  return $status_links;
}

Change the text of the ‘All’ link to ‘All Comments’.

add_filter('comment_status_links', 'change_all_link_text');
function change_all_link_text($status_links) {
  $status_links['all'] = str_replace('All', 'All Comments', $status_links['all']);
  return $status_links;
}

Add a custom link named ‘Unreplied’ to display comments that have not been replied to.

add_filter('comment_status_links', 'add_unreplied_link');
function add_unreplied_link($status_links) {
  $unreplied_count = 10; // Replace with the actual count of unreplied comments
  $status_links['unreplied'] = '<a href="edit-comments.php?show_unreplied=true">Unreplied (' . $unreplied_count . ')</a>';
  return $status_links;
}

Add a separator (a vertical bar) between the comment status links.

add_filter('comment_status_links', 'add_separator_between_links');
function add_separator_between_links($status_links) {
  foreach ($status_links as $key => $link) {
    $status_links[$key] = $link . ' | ';
  }
  return $status_links;
}

Change the order of the comment status links to display ‘Approved’, ‘Pending’, ‘Spam’, ‘Trash’, ‘All’, and ‘Mine’.

add_filter('comment_status_links', 'change_link_order');
function change_link_order($status_links) {
  $new_order = ['approved', 'pending', 'spam', 'trash', 'all', 'mine'];
  $reordered_links = [];
  foreach ($new_order as $key) {
    $reordered_links[$key] = $status_links[$key];
  }
  return $reordered_links;
}

Leave a Comment

Your email address will not be published. Required fields are marked *