Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds screen option for toggle the display of the comment column in WP Dashboard comments list.
<?php
/**
* Plugin Name: WPSE356451 Toggle Comment Column
* Description: Adds screen option for toggle the display of the comment column in WP Dashboard comments list.
* Plugin URI: https://wordpress.stackexchange.com/questions/356451/add-a-comment-on-off-option-in-screen-options-for-comments
* Author: Tim Elsass
* Author URI: tim.ph
*/
/**
* Removes core's comment column and adds a screen option for toggling "Comment" column display.
*/
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;
} );
/**
* Handles output of "Comment" column in WP Dashboard comments list.
*/
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment