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

Filters the columns displayed in the Posts list table.


Description Description


Parameters Parameters

$post_columns

(string[]) An associative array of column headings.

$post_type

(string) The post type slug.


Top ↑

Source Source

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

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.


Top ↑

User Contributed Notes 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 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.