apply_filters( "manage_{$screen->id}_columns", string[] $columns )

Filters the column headers for a list table on a specific screen.


Description Description

The dynamic portion of the hook name, $screen->id, refers to the ID of a specific screen. For example, the screen ID for the Posts list table is edit-post, so the filter for that screen would be manage_edit-post_columns.


Top ↑

Parameters Parameters

$columns

(string[]) The column header labels keyed by column ID.


Top ↑

Source Source

File: wp-admin/includes/screen.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by stevenlinx

    Example migrated from Codex:

    Add Columns

    Suppose you have a ‘books’ custom post type and you want to add the publisher and book author to the list of columns.

    add_filter('manage_books_posts_columns' , 'book_cpt_columns');
    
    function book_cpt_columns($columns) {
    	$new_columns = array(
    		'publisher' => __('Publisher', 'ThemeName'),
    		'book_author' => __('Book Author', 'ThemeName'),
    	);
    
        return array_merge($columns, $new_columns);
    }
    

    Replace Columns

    Here’s another example that removes and replaces some of the columns.

    add_filter('manage_books_posts_columns' , 'book_cpt_columns');
    
    function book_cpt_columns($columns) {
    	unset(
    		$columns['author'],
    		$columns['comments']
    	);
    
    	$new_columns = array(
    		'publisher' => __('Publisher', 'ThemeName'),
    		'book_author' => __('Book Author', 'ThemeName'),
    	);
    
        return array_merge($columns, $new_columns);
    }
    

    Note that unlike an array data type, the unset PHP function accepts arguments in which the last argument should NOT end with a comma.

    Hide Columns

    Here is an example of how to remove or (hide) columns from Pages / Posts and Custom Post Types without adding any.

    You can also add the name of the custom-post type and filter them out in there too… But if you have 5 custom post types you will need five different filters.

    Note: Replace the text CUSTOMPOSTTYPE below with the name of your post type.

    // Filter pages
    add_filter( 'manage_edit-page_columns', 'my_columns_filter',10, 1 );	
    
    // Filter Posts
    add_filter( 'manage_edit-post_columns', 'my_columns_filter',10, 1 );
    
    // Custom Post Type
    add_filter( 'manage_edit-CUSTOMPOSTTYPE_columns', 'my_columns_filter',10, 1 );
    
    function my_columns_filter( $columns ) {
       unset($columns['author']);
       unset($columns['categories']);
       unset($columns['tags']);
       unset($columns['comments']);
       
       return $columns;
    }
    

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