How to display post and page ID in WordPress admin


Back to the old WordPress 2.5, the post ID was displayed in WordPress admin. Afterwards, this feature was removed. I didn’t check why but now and then I feel it necessary to get the post ID easily.

An easy way is to visit the edit page of a post and check the URL. It looks something like:

10586 is the post ID.

It should have been much easier.

Follow this tutorial and the final result is to reveal the ID in the admin post lists.

Final work of this post

The codes should go to your theme’s functions.php, or a separate plugin which is what I recommended. Also to save your time, the whole pieces of codes in this tutorial is compressed to a simple plugin that you can download at the bottom.

Add custom columns

We’ll use a filter to add custom columns to admin post lists and an action to display the content.

manage_posts_columns and manage_posts_custom_column

It should work well with this little piece of code to reveal the post ID.

What if you want to reveal the page ID? How about category ID, tag ID, and even comment ID?

The solution is similar as above, you just have to find the right hooks. The common form is manage_[post_type_or_element]_columns and manage_[post_type_or_element]_custom_column.

Below is the full hooks for media, users, categories, custom post types and taxonomies.

So far you should see the ID for all the posts, comments, users and taxonomies. But it appear at the end and the width seams a little more exceeding what’s enough.

ID goes to the end with much width

We have to make some additional tweaks.

Pulling the ID to the front

We just need to do some changes on the ws_cutom_columns_head function.
Following codes will place the ID to the front, right after the checkbox.

And below is the codes to adjust the column width

Change the number as you like.

Here is the final whole codes.

Hope you find this useful. And here is the working plugin you can instant activate to use on your WordPress blogs.


Author: Leo

My name is Leo who’s behind this blog. I’ve been working with wordpress since 2010. I’ll write about themes, plugins, tutorials and all about wordpress here. Hope you find it useful!

Leave a Reply

Your email address will not be published. Required fields are marked *