Using WordPress ‘manage_pages_custom_column’ PHP action

The manage_pages_custom_column WordPress action fires in each custom column on the Posts list table for hierarchical post types, such as pages.

Usage

add_action('manage_pages_custom_column', 'your_custom_function', 10, 2);

function your_custom_function($column_name, $post_id) {
    // your custom code here

}

Parameters

  • $column_name (string) – The name of the column to display.
  • $post_id (int) – The current post ID.

More information

See WordPress Developer Resources: manage_pages_custom_column

Examples

Add a custom column to display the post ID

// Register the custom column
function your_custom_column($columns) {
    $columns['post_id'] = 'Post ID';
    return $columns;
}
add_filter('manage_pages_columns', 'your_custom_column');

// Display the post ID in the custom column
function display_post_id($column_name, $post_id) {
    if ('post_id' === $column_name) {
        echo $post_id;
    }
}
add_action('manage_pages_custom_column', 'display_post_id', 10, 2);
// Register the custom column
function your_custom_column($columns) {
    $columns['featured_image'] = 'Featured Image';
    return $columns;
}
add_filter('manage_pages_columns', 'your_custom_column');

// Display the featured image in the custom column
function display_featured_image($column_name, $post_id) {
    if ('featured_image' === $column_name) {
        $featured_img_url = get_the_post_thumbnail_url($post_id, 'thumbnail');
        echo '<img src="' . esc_url($featured_img_url) . '" alt="Featured Image">';
    }
}
add_action('manage_pages_custom_column', 'display_featured_image', 10, 2);

Display the word count of the post content

// Register the custom column
function your_custom_column($columns) {
    $columns['word_count'] = 'Word Count';
    return $columns;
}
add_filter('manage_pages_columns', 'your_custom_column');

// Display the word count in the custom column
function display_word_count($column_name, $post_id) {
    if ('word_count' === $column_name) {
        $post_content = get_post_field('post_content', $post_id);
        $word_count = str_word_count(strip_tags($post_content));
        echo $word_count;
    }
}
add_action('manage_pages_custom_column', 'display_word_count', 10, 2);

Show the author’s email in a custom column

// Register the custom column
function your_custom_column($columns) {
    $columns['author_email'] = "Author's Email";
    return $columns;
}
add_filter('manage_pages_columns', 'your_custom_column');

// Display the author's email in the custom column
function display_author_email($column_name, $post_id) {
    if ('author_email' === $column_name) {
        $post_author_id = get_post_field('post_author', $post_id);
        $author_email = get_the_author_meta('email', $post_author_id);
        echo $author_email;
    }
}
add_action('manage_pages_custom_column', 'display_author_email', 10, 2);