Add post id to admin column in WordPress


Following example will shows how to add a custom column ‘ID’ in WordPress post.

To add a custom column for page ,  post in WordPress use ‘manage_post_posts_columns’ filter. I create a function named wp_add_post_ids_to_columns() which called via ‘manage_post_posts_columns’ filter to add column.

function wp_add_post_ids_to_columns($columns){

$columns[‘wp_post_ids’] = ‘ID’;
return $columns;
}
add_filter(‘manage_post_posts_columns’,’wp_add_post_ids_to_columns’);

Following function will called via ‘manage_posts_custom_column’ wordpress action. while we edit posts.

function wp_render_post_columns($column_name,$id){
switch( $column_name ){
case ‘wp_post_ids’:
echo $id;
break;
}
}

add_action(‘manage_posts_custom_column’,’wp_render_post_columns’,10,2);

Advertisements

1 thought on “Add post id to admin column in WordPress”

  1. Howdy! This is my first visit to your blog! We are a collection of volunteers and starting a new project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a extraordinary job!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s