Add Snippet To Project
It’s not unusual to want a lean, clean interface when managing your WordPress site. Extraneous columns in the media library can clutter your view and detract from efficient workflow. Hence, removing these can lead to a more streamlined backend environment. In this article, we will guide you through the steps necessary to remove media columns in your WordPress site, helping you maintain an organized and simplified workspace.
function wpturbo_remove_media_columns( $columns ) {
unset($columns['author']);
unset($columns['comments']);
unset($columns['date']);
// this column is added by other plugin
// so you may want to make sure it exist before removing it
if( isset( $columns['seo'] ) ){
unset($columns['seo']);
}
return $columns;
}
add_filter('manage_media_columns' , 'wpturbo_remove_media_columns');
The given PHP code block is created to remove some unnecessary or undesired columns in the Media Library page in your WordPress admin dashboard.
Here is a breakdown explaining how this piece of code works:
The function wpturbo_remove_media_columns( $columns ) accepts a single parameter $columns, which is an associative array where the keys represent the column IDs and the corresponding values represent the text to be displayed as a header for said column.
Next, we use the unset PHP function to delete certain elements from the array. We’re removing ‘author,’ ‘comments,’ and ‘date’ columns.
unset($columns['author']);
unset($columns['comments']);
unset($columns['date']);
The ‘author,’ ‘comments,’ and ‘date’ columns, which are often included by default in the media library list view, will no longer be displayed after implementing this snippet.
We then account for the potential presence of a seo column, which may have been inserted by an SEO plugin. Before using unset(), it is best to make sure that this column exists to avoid potential errors. This can be done using the isset() function:
if( isset( $columns['seo'] ) ){
unset($columns['seo']);
}
Finally, the modified $columns array is returned:
return $columns;
And to ensure WordPress utilizes this custom function, we link it to the filter hook manage_media_columns.
add_filter('manage_media_columns' , 'wpturbo_remove_media_columns');
This filter hook allows us to change or remove the default columns in the Media Library page in the WordPress admin view. Now, every time the Media Library is called, the function wpturbo_remove_media_columns will be performed. Hence, the selected column headers will be removed from the display.
