manage_posts_columns is a filter applied to the columns shown on the manage posts screen. It’s applied to posts of all types except pages. To add a custom column for pages, hook the manage_pages_columns filter. To add a custom column for specific custom post types, hook the manage_{$post_type}_posts_columns filter.
Built-in Column Types
Listed in order of appearance. By default, all columns supported by the post type are shown.
title Post title. Includes “edit”, “quick edit”, “trash” and “view” links. If $mode (set from $_REQUEST[‘mode’]) is ‘excerpt’, a post excerpt is included between the title and links.
To add a custom column, hook into this filter, and add an item to the $post_columns array. The key should be a string ID, and the value should be the human-readable text to display in the column’s header.
<?php
namespace DemoPlugin;
const COLUMN_ID = 'publisher';
/**
* Register the custom column.
*
* @param array $columns Existing columns.
* @return array Columns with custom column added.
*/
function register_column( array $columns ) : array {
$columns[ COLUMN_ID ] = __( 'Publisher', 'demo-plugin' );
return $columns;
}
add_action( 'manage_posts_columns', __NAMESPACE__ . '\\register_column' );
// You will likely also want to hook into 'manage_posts_custom_column' to
// output the column's value.
function render_column( string $column_id ) {
if ( $column_id !== COLUMN_ID ) {
return;
}
$post = get_post();
echo esc_html( get_post_meta( $post->ID, '_demo_publisher', true ) );
}
add_action( 'manage_posts_custom_column', __NAMESPACE__ . '\\render_column' );
If you only want to modify the table view of your Posts, you can use the hooks:
manage_post_posts_columns
andmanage_post_posts_custom_column
To add a custom column, hook into this filter, and add an item to the
$post_columns
array. The key should be a string ID, and the value should be the human-readable text to display in the column’s header.If the new custom column is only for the default post type, then it needs to check the post type.
Example: To add custom featured image thumbnail column in the post.
Example migrated from Codex:
To add a column showing whether a post is sticky or not:
To actually display whether or not a post is sticky, hook the manage_posts_custom_column action.
To add and remove columns from backand posts > all post .
To add and remove columns from backand posts > all post .
Example: This will remove the author, categories, tags and comment columns from backend Posts > All Posts section.