Add Snippet To Project
By default, WordPress displays the number of comments in a column on the Pages screen in the admin dashboard. While this can be helpful for blog posts, it might not be as useful for pages. If you’re looking to clean up the interface or just don’t want to see comment counts for your pages, you can remove this column from view with a few simple steps. Keep reading to find out how.
function wpturbo_remove_comments_count_column( $columns ) {
unset( $columns['comments'] );
return $columns;
}
add_filter( 'manage_pages_columns', 'wpturbo_remove_comments_count_column' );
The primary objective of the code snippet is to remove the comments count column that appears in the WordPress pages table. The wpturbo_remove_comments_count_column()
function is used to perform this operation.
The first line of the code snippet adds the desired functionality by intercepting a filter that WordPress uses to generate columns in the manage_pages_columns
table. This function is called with $columns
as a parameter, which is an associative array with the available column headers and their corresponding labels.
The unset()
function is then called with the $columns['comments']
key parameter. This key refers to the comments count column that we want to delete. Once the column is removed, the function returns the modified array:
function wpturbo_remove_comments_count_column( $columns ) {
unset( $columns['comments'] );
return $columns;
}
The final step is to add the newly created filter to the appropriate action. We use the manage_pages_columns
hook since we want to modify the pages table specifically. This line of code hooks the wpturbo_remove_comments_count_column()
function to the filter:
add_filter( 'manage_pages_columns', 'wpturbo_remove_comments_count_column' );
This will make sure that whenever the page table is displayed, the comments count column will not be there.