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:
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:
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.
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. 😉