• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Display the post ID in WordPress administration bar

Discover in this tutorial how to display the post ID you are visiting in WordPress top admin bar using code.

If, like me, you also “tinker” a lot with WordPress conditional tags, surely you’ve ever missed knowing the ID of a particular post.

In a previous tutorial I explained how you can display the posts ID in a WordPress admin new column.

But recently, in a project I was working on, I missed being able to see it when visiting the post frontend. So I looked for a quick and easy way to get the ID at a glance.

This is the final result:

WordPress admin bar showing the ID of the visited post
WordPress admin bar showing the ID of the visited post

If you have also found yourself in the same situation, I’m sure this tutorial will come in handy. 😉

Snippet to display the identifier of the visited post in WordPress “admin bar”

Add the following code at the end of functions.php or in your functionality plugin:

To see this and another 919 code snippets of this website, login or subscribe here.

In this case, you use the hook admin_bar_menu in combination with the global variable $post to display the post identifier in the top WordPress admin bar.

You also use the priority of “40”, so that it is displayed right after the site name (My Osom Site, in this example), but you can modify it if you prefer it to appear before or after.

Conclusion

With a few lines of code you can get the post identifier you are visiting displayed in the WordPress admin bar.

Any questions? I read you in the comments.

And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉

Header PHP WordPress

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?