The manage_{$post->post_type}_posts_custom_column WordPress action allows you to customize the content of a specific custom column in the Posts list table, depending on the post type.
Usage
add_action('manage_{$post->post_type}_posts_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_{$post->post_type}_posts_custom_column
Examples
Display a custom field value in a custom column
To display the value of a custom field called ‘price’ in a custom column:
add_action('manage_post_posts_custom_column', 'display_price_custom_column', 10, 2); function display_price_custom_column($column_name, $post_id) { if ('price' === $column_name) { $price = get_post_meta($post_id, 'price', true); echo '$' . esc_html($price); } }
Show a post’s featured image in a custom column
To show the featured image of a post in a custom column:
add_action('manage_post_posts_custom_column', 'display_featured_image_custom_column', 10, 2); function display_featured_image_custom_column($column_name, $post_id) { if ('featured_image' === $column_name) { $image = get_the_post_thumbnail($post_id, 'thumbnail'); echo $image; } }
Display the word count of a post in a custom column
To show the word count of a post in a custom column:
add_action('manage_post_posts_custom_column', 'display_word_count_custom_column', 10, 2); function display_word_count_custom_column($column_name, $post_id) { if ('word_count' === $column_name) { $content = get_post_field('post_content', $post_id); $word_count = str_word_count(strip_tags($content)); echo $word_count; } }
Show the number of comments on a page in a custom column
To display the number of comments on a page in a custom column:
add_action('manage_page_posts_custom_column', 'display_comments_count_custom_column', 10, 2); function display_comments_count_custom_column($column_name, $post_id) { if ('comments_count' === $column_name) { $comments_count = wp_count_comments($post_id)->approved; echo $comments_count; } }
Display a custom taxonomy term in a custom column
To show the terms of a custom taxonomy called ‘location’ in a custom column:
add_action('manage_post_posts_custom_column', 'display_location_custom_column', 10, 2); function display_location_custom_column($column_name, $post_id) { if ('location' === $column_name) { $terms = wp_get_post_terms($post_id, 'location', array('fields' => 'names')); echo implode(', ', $terms); } }