wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Add post ID to posts, pages admin columns

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will add ID to post and pages admin columns.

snippet :  PHPcopy
    add_filter('manage_posts_columns', 'posts_columns_id', 5);
    add_action('manage_posts_custom_column', 'posts_custom_id_columns', 5, 2);
    add_filter('manage_pages_columns', 'posts_columns_id', 5);
    add_action('manage_pages_custom_column', 'posts_custom_id_columns', 5, 2);
function posts_columns_id($defaults){
    $defaults['wps_post_id'] = __('ID');
    return $defaults;
}
function posts_custom_id_columns($column_name, $id){
	if($column_name === 'wps_post_id'){
        	echo $id;
    }
}

Did you like this post? If so please share it with your friends. Thanks!

  • Pingback: Add a Column to Easily Note the Post ID()

  • Anonymous

    Is there a way to reduce the width of that extra column?

  • Pingback: Daily Tip: How to Display Post and Page IDs in the WordPress Admin - WPMU.org()

  • Arny

    Great! Like glvr, would it be possible to reduce the width of the extra column? Thanks Kevin!

  • Patrick Samphire

    For those asking how to reduce the width of the column, add the following to your functions.php file:

    add_action(‘admin_head’, ‘custom_admin_styling’);
    function custom_admin_styling() {
    echo ”;
    echo ‘th#wps_post_id{width:50px;}';
    echo ”;
    }

    Or whatever width you want.

  • Pingback: Wordpress Sidebar Widgets - a Trifecta of Perfect Plugin Magic()

  • Pingback: Wordpress Admin - How My Custom Posts List Rolls()

  • Adam

    Is there a way to show the IDs for only 1 post type? e.g. a custom post type?

    • http://wpsnipp.com Kevin Chard

      Hi Adam,
      if you want to only display it with a custom post type, remove the add_action, add_filter in the above and replace them with this eg:

      add_filter(‘manage_edit-POSTTYPENAME_columns’, ‘posts_columns_id’, 5);
      add_action(‘manage_posts_custom_column’, ‘posts_custom_id_columns’, 5, 2);

      replace POSTTYPENAME with your post type name and your good to go.