Using WordPress ‘manage_comments_nav’ PHP action

The manage_comments_nav WordPress PHP action fires after the Filter submit button for comment types.

Usage

add_action('manage_comments_nav', 'your_custom_function', 10, 2);

function your_custom_function($comment_status, $which) {
    // your custom code here
}

Parameters

  • $comment_status (string): The comment status name. Default ‘All’.
  • $which (string): The location of the extra table nav markup: ‘top’ or ‘bottom’.

More information

See WordPress Developer Resources: manage_comments_nav

Examples

Add custom content above the comment table

Add custom content at the top of the comment table.

add_action('manage_comments_nav', 'add_custom_content_above_comments', 10, 2);

function add_custom_content_above_comments($comment_status, $which) {
    if ($which == 'top') {
        echo '**Your custom content here**';
    }
}

Add custom content below the comment table

Add custom content at the bottom of the comment table.

add_action('manage_comments_nav', 'add_custom_content_below_comments', 10, 2);

function add_custom_content_below_comments($comment_status, $which) {
    if ($which == 'bottom') {
        echo '**Your custom content here**';
    }
}

Display total number of comments

Display the total number of comments on the site.

add_action('manage_comments_nav', 'display_total_comments', 10, 2);

function display_total_comments($comment_status, $which) {
    if ($which == 'top') {
        $total_comments = wp_count_comments();
        echo 'Total comments: ' . $total_comments->total_comments;
    }
}

Display a custom message for a specific comment status

Display a custom message when a specific comment status is selected.

add_action('manage_comments_nav', 'display_custom_message_for_status', 10, 2);

function display_custom_message_for_status($comment_status, $which) {
    if ($comment_status == 'pending' && $which == 'top') {
        echo 'Custom message for pending comments';
    }
}

Add custom CSS class to the comment table

Add a custom CSS class to the comment table based on the comment status.

add_action('manage_comments_nav', 'add_custom_css_class_to_comment_table', 10, 2);

function add_custom_css_class_to_comment_table($comment_status, $which) {
    if ($which == 'top') {
        echo '<style>.comments-box { border: 1px solid red; }</style>';
    }
}