do_action( 'manage_pages_custom_column', string $column_name, int $post_id )

Fires in each custom column on the Posts list table.


Description Description

This hook only fires if the current post type is hierarchical, such as pages.


Parameters Parameters

$column_name

(string) The name of the column to display.

$post_id

(int) The current post ID.


Top ↑

Source Source

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

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.5.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Khoi Pro

    To add “Template” column into page list:

    add_filter( 'manage_pages_columns', 'page_column_views' );
    add_action( 'manage_pages_custom_column', 'page_custom_column_views', 5, 2 );
    function page_column_views( $defaults )
    {
    	$defaults['page-layout'] = __('Template', 'textdomain');
    	return $defaults;
    }
    function page_custom_column_views( $column_name, $id )
    {
    	if ( $column_name === 'page-layout' ) {
    		$set_template = get_post_meta( get_the_ID(), '_wp_page_template', true );
    		if ( $set_template == 'default' ) {
    			echo __('Default Template', 'textdomain');
    		}
    		$templates = get_page_templates();
    		ksort( $templates );
    		foreach ( array_keys( $templates ) as $template ) :
    			if ( $set_template == $templates[$template] ) echo $template;
    		endforeach;
    	}
    }
    

    To add to other post types (not post, page or attachment…):

    The hooks to create custom columns and their associated data for a custom post type are manage_{$post_type}_posts_columns and manage_{$post_type}_posts_custom_column respectively, where {$post_type} is the name of the custom post type.

    // Add the custom columns to the book post type:
    add_filter( 'manage_book_posts_columns', 'set_custom_edit_book_columns' );
    function set_custom_edit_book_columns($columns) {
        unset( $columns['author'] );
        $columns['book_author'] = __( 'Author', 'textdomain' );
        $columns['publisher'] = __( 'Publisher', 'textdomain' );
    
        return $columns;
    }
    
    // Add the data to the custom columns for the book post type:
    add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 );
    function custom_book_column( $column, $post_id ) {
        switch ( $column ) {
    
            case 'book_author' :
                $terms = get_the_term_list( $post_id , 'book_author' , '' , ',' , '' );
                if ( is_string( $terms ) )
                    echo $terms;
                else
                    _e( 'Unable to get author(s)', 'textdomain' );
                break;
    
            case 'publisher' :
                echo get_post_meta( $post_id , 'publisher' , true ); 
                break;
    
        }
    }
    

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