The manage_posts_columns hook is used to add or remove columns from the post listing table in the WordPress admin panel. This hook allows developers to customize the display of post information by defining new columns or removing existing ones.
By default, the post listing table in the WordPress admin shows columns such as Title, Author, Categories, Tags, Comments, and Date. However, sometimes you may need to add or remove certain columns to better suit your needs.
To add a new column, you can use the manage_posts_columns hook to define the column name and content. To remove a column, you can simply unset the corresponding array key.
Here’s an example usage code that demonstrates how to add a new column to the post listing table:
function custom_post_column($columns) {
$columns['featured_image'] = __( 'Featured Image', 'text-domain' );
return $columns;
}
add_filter( 'manage_posts_columns', 'custom_post_column' );
In this example, we’re adding a new column called "Featured Image" to the post listing table. The function custom_post_column
adds the new column to the $columns
array and returns it. Finally, the add_filter
function is used to hook into the manage_posts_columns
hook and apply our custom post column.
WordPress snippets using the manage_posts_columns hook
-
show posts id's on backend
-
Add a column to posts & post types lists with featured image
-
How to Remove Post Columns in WordPress: A Detailed Guide
-
How to Remove Author from WordPress Posts: A Beginner’s Guide
-
How to Display Post Attachment Count in the Admin Column in WordPress
-
code to take a selection of meta fields from a Cpt and present them in a pdf