0

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!

comments

1 Answer 1

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.

1
  • Thanks a lot, man! The code did the trick!
    – Alex
    Jan 16, 2020 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.