apply_filters( 'manage_posts_columns', string[] $post_columns, string $post_type )

Filters the columns displayed in the Posts list table.


Parameters

$post_columns string[]
An associative array of column headings.
$post_type string
The post type slug.

Top ↑

More Information

  • 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.

    • cb Checkbox for bulk actions.
    • 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.
    • author Post author.
    • categories Categories the post belongs to.
    • tags Tags for the post.
    • comments Number of pending comments.
    • date The date and publish status of the post.

Top ↑

Source

File: wp-admin/includes/class-wp-posts-list-table.php. View all references

$posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );


Top ↑

Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Ryan McCue

    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' );
  2. Skip to note 2 content
    Contributed by Keramot UL Islam

    If the new custom column is only for the default post type, then it needs to check the post type.

    function my_add_new_columns($columns) {
        $post_type = get_post_type();
        if ( $post_type == 'post' ) {
            $new_columns = array(
                'my_featured' => esc_html__( 'Featured', 'text_domain' ),
            );
            return array_merge($columns, $new_columns);
        }
    }
    add_filter( 'manage_posts_columns',  'my_add_new_columns' );
  3. Skip to note 3 content
    Contributed by codegearthemes

    Example: To add custom featured image thumbnail column in the post.

    function wpdocs_posts_thumb_columns( $columns ) {
        $post_new_columns = array(
           'post_thumbs' => esc_html__( 'Thumbs', 'text_domain' ),
        );
        return array_merge( $columns, $post_new_columns );
    }
    add_filter( 'manage_posts_columns', 'wpdocs_posts_thumb_columns', 5 );
    
    function wpdocs_posts_custom_columns( $column_name, $id ) {
        if ( 'post_thumbs' === $column_name ) {
            the_post_thumbnail( 'thumbnail' );
        }
    }
    add_action( 'manage_posts_custom_column', 'wpdocs_posts_custom_columns', 5, 2 );
  4. Skip to note 4 content
    Contributed by Steven Lin

    Example migrated from Codex:

    To add a column showing whether a post is sticky or not:

    function add_sticky_column( $columns ) {
    	$columns['sticky'] = __('Sticky');
            return $columns;
    }
    add_filter( 'manage_posts_columns' , 'add_sticky_column' );

    To actually display whether or not a post is sticky, hook the manage_posts_custom_column action.

  5. Skip to note 5 content
    Contributed by Shorifpatwary

    To add and remove columns from backand posts > all post .

    if ( ! function_exists( 'wpdocs_manage_custom_posts_column' ) ) {
        function wpdocs_manage_custom_posts_column( $columns ) {
    	// delete some columns from dashboard post page . 
    
            unset( $columns['categories'] );
            unset( $columns['tags'] );
    		
    	// add a customs column in dashboard post page .  
    	$post_type = get_post_type();
    	if ( $post_type == 'post' ) {
    		$new_columns = array(
    			'my_featured' => esc_html__( 'Featured', 'aquila' ),
    			'my_column' => esc_html__( 'My Column ', 'aquila' ),
    		);
    		$custom_columns = array_merge($columns, $new_columns);
    	}
    
    	// return final custom columns variable . 
            return $custom_columns;
        }
        add_filter( 'manage_posts_columns', 'wpdocs_manage_custom_posts_column' );
    }
  6. Skip to note 6 content
    Contributed by Shorifpatwary

    To add and remove columns from backand posts > all post .

    if ( ! function_exists( 'custom_manage_posts_column' ) ) {
        function manage_custom_posts_column( $columns ) {
    		// delete some columns from dashboard post page . 
            unset( $columns['categories'] );
            unset( $columns['tags'] );		
    		// add a customs column in dashboard post page .  
    		$post_type = get_post_type();
    		if ( $post_type == 'post' ) {
    			$new_columns = array(
    				'my_featured' => esc_html__( 'Featured', 'text_domain' ),
    				'my_column'   => esc_html__( 'My Column', 'text_domain' ),
    			);
    			$custom_columns = array_merge($columns, $new_columns);
    		}
    	// return final custom columns variable . 
            return $custom_columns;
        }
    }
        add_filter( 'manage_posts_columns', 'manage_custom_posts_column' );
  7. Skip to note 7 content
    Contributed by Imran Sayed

    Example: This will remove the author, categories, tags and comment columns from backend Posts > All Posts section.

    if ( ! function_exists( 'custom_manage_posts_column' ) ) {
    	function custom_manage_posts_column( $columns ) {
    		unset( $columns['author'] );
    		unset( $columns['categories'] );
    		unset( $columns['tags'] );
    		unset( $columns['comments'] );
    		return $columns;
    	}
    }
    if ( has_filter( 'manage_posts_columns' ) ) {
    	add_filter( 'manage_posts_columns', 'custom_manage_posts_column' );
    }

You must log in before being able to contribute a note or feedback.