Coding

How to find a tag, category, post or page ID in WordPress

posted on by - 1174 views

WordPress, as almost every other content management system, uses an ID organized structure. That means every item – a post, a page, a category, a tag, a custom taxonomy term… – has its own, unique ID, which is a number that identify that specific element without doubts.

Speaking of WordPress, knowing IDs of elements can be useful for many things: for example, we can have custom styles only for specific pages or posts, or some plugin or widget we’re using is specifically asking for elements IDs. While finding an ID may be obvious for someone that’s using WordPress for some time, a new user could not know where to look. And that’s why this post exists (it’s for you, new WordPress user, yes).

How to find the post ID in WordPress

Let’s start with posts. We have two ways to find the post ID in WordPress.

The first one, is by using the CSS classes WordPress automatically appends to the body HTML element. So we can just visit the post we want to know the ID of, and inspect the page with our browser. Then we just navigate inside the source code and find the body classes: there, we will find something like postid-000, where 000 is the number we need.

Here’s an image for a better understanding.

So, the ID of that particular post is 145. Easy, huh?

So that was the first way to do that. The second way to find the post ID requires the access to the admin panel of WordPress. This is easy too: the only thing to do is open the post edit page, and looking right at the URL in our address bar. It should be something like this:

The ID of this very post, in this case, is 167. And it works exactly the same for pages, categories or tags: just go to the page you want to check, and get a look to the code (inspect the page with your browser). Or else, go to your admin page, enter the item you want to find the ID of, and look at the address bar.