admin管理员组

文章数量:1404605

In the Wordpress dashboard, I want to be able to add the option to turn off the Comment column. Can I do that via functions.php? I found a plugin that does a lot of things, but since I need this one small thing, I thought to keep it light.

I really hope someone knows this. Thanks!

In the Wordpress dashboard, I want to be able to add the option to turn off the Comment column. Can I do that via functions.php? I found a plugin that does a lot of things, but since I need this one small thing, I thought to keep it light.

I really hope someone knows this. Thanks!

Share Improve this question asked Jan 15, 2020 at 18:16 AlexAlex 1811 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

To achieve this, you should filter the manage_edit-comments_columns filter to remove the core comment column, and add a custom comment column so the checkbox shows up in the screen options tab.

For the output of comments, you would then need to get comment_content from the comment for display output in the manage_comments_custom_column hook.

This is an example of the above code:

add_filter( 'manage_edit-comments_columns', function( $columns ) {

    // Remove core comment column.
    unset( $columns['comment'] );

    // Custom "Comment" column to add to screen options and output.
    $custom_column = [ 'WPSE356451_add_comment' => 'Comment' ];
    $columns = array_slice( $columns, 0, 2, true ) + $custom_column + array_slice( $columns, 2, NULL, true );

    return $columns;
} );

add_action( 'manage_comments_custom_column', function( $column, $comment_ID ) {
    global $comment;

    // Check for custom comment column and handle output.
    if ( 'WPSE356451_add_comment' === $column ) {
        echo $comment->comment_content;
    }
}, 10, 2 );

Here's a gist for the code above, and a direct plugin .zip for download.

本文标签: Add a Comment onoff option in Screen Options for Comments