X

Add Post ID to Posts and Pages Admin Columns

Snippets by IsItWP

Are you looking for a way to add post ID column to admin posts list?

You need the post IDs for multiple purposes like adding a post ID to some shortcode. Normally, it’s not available with the posts and pages. You can add another admin column to show post ID information.

Instructions: Add the following code to the functions.php file of your WordPress theme.

    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;
    }
}

You may also enjoy adding post ID column to posts list.

Comments   Leave a Reply

  1. Thanks this links works for me.

    1. Hey James, you’re welcome!

  2. This is great in it’s simplicity. But would you know how to do the same for the post excerpt? I’ve been looking a clean working solution for days with no luck….

    1. You may be able to use this function inside the posts_custom_id_columns() function: https://developer.wordpress.org/reference/functions/get_the_excerpt/

  3. Can I assign custom ID to post or start id from one series.

    1. While this is possible to do by editing the database, generally it’s not recommended to assign a custom ID to a post. Doing so incorrectly could cause problems.

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

    1. 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.

  5. Wordpress Admin - How My Custom Posts List Rolls March 2, 2014 at 2:31 am

    […] [Source] […]

  6. Wordpress Sidebar Widgets - a Trifecta of Perfect Plugin Magic February 24, 2014 at 9:18 am

    […] you’d prefer to place code in your functions file and shave off yet another plugin, try this block of code for in your functions file and you won’t need Reveal […]

  7. Patrick Samphire December 17, 2013 at 3:16 pm

    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.

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

  9. Daily Tip: How to Display Post and Page IDs in the WordPress Admin - WPMU.org July 23, 2012 at 11:44 pm

    […] very useful snippet comes to you courtesy of our friend Kevin Chard of WPSNIPP.com, where they’re now rocking […]

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

  11. Add a Column to Easily Note the Post ID January 4, 2012 at 8:02 am

    […] an easier way to find the Post ID, by adding a column in the post editor screen.Well, it seems that WP Snipp pipped me to the post as they just published a post doing exactly that. So rather than go through […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!