do_action( ‘manage_pages_custom_column’, string $column_name, int $post_id )

Fires in each custom column on the Posts list table.

Description

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

Parameters

$column_namestring
The name of the column to display.
$post_idint
The current post ID.

More Information

Combined with the manage_pages_columns filter, this allows you to add or remove (unset) custom columns to the list page pages. Note that if you are using custom post types and it has ‘hierarchical‘ => true, then you will need to use this action hook and not manage_$post_type_posts_custom_column.

Source

do_action( 'manage_pages_custom_column', $column_name, $post->ID ); 

Changelog

VersionDescription
2.5.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    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; } }
  2. Skip to note 4 content

    Example migrated from Codex:

    Once you have added your column (for this example, thumbnail), the featured image can be displayed for that page in the new thumbnail column.

    function custom_page_column_content( $column_name, $post_id ) {	if ( $column_name == 'thumbnail' ) {	$post_thumbnail_id = get_post_thumbnail_id( $post_id );	if ( $post_thumbnail_id ) {	$post_thumbnail_img = wp_get_attachment_image_src( $post_thumbnail_id, 'thumbnail' );	echo '<img src="' . $post_thumbnail_img[0] . '" />';	}	} } add_action( 'manage_pages_custom_column', 'custom_page_column_content', 10, 2 );

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