Search for a plugin or theme

Search
Generic filters

How to Get and Find WordPress Page and Post ID

You are currently viewing How to Get and Find WordPress Page and Post ID

Every WordPress page or post has a unique ID number. In some scenarios, we will need to use that ID when using a function or a custom plugin.

There are a few ways to reveal the IDs, some methods are manually, and others are by using a plugin.

This article will show you how to find a WordPress page ID in every possible way.

Why Find Post or Page ID in WordPress

The main reason for knowing and using the ID of a page or a post would be when using a custom function or creating a template.

You’ll often need to target a specific WordPress website page in those cases. Because every page or post has a unique ID number, that is the best way to target a page.

For example, one of our previous posts showed you how to use a function to redirect an empty checkout page. The function needed the page ID of the destination page for the redirect rule to work. That is a classic reason when to use a page or post IDs.

The function above uses the specific ID of the destination page. It wouldn’t be able to be executed without it.

How to Find Page ID With a Plugin

As you already know, there are WordPress plugins for everything; many will display the ID of a page or a post in a dedicated column. However, in this tutorial, I would like to focus on a specific one.

This article will show you how to use the Catch IDs plugin to reveal the IDs of pages, posts, custom post types, categories, tags, and media such as images and videos.

  1. Navigate to Plugins -> Add New, search for Catch IDs, and install and activate itInstall the catch ID plugin

  2. Once activated the plugin, a new ID column will be added to the left of the page or post name.
    You can also see the ID column in the media, categories, and tags pages.New ID Column

  3. Optional: If you don’t see the new ID column on your admin screen, navigate to the Catch IDs tab on the left and ensure all the options are turned on and green.Catch ID plugin settings

While using a plugin is the most straightforward way, some of you may want to get the ID without installing a dedicated plugin, and we can do it in three different ways.

There are many ways to discover the ID without a plugin, and now I will show you the most common ones.

How to Find Page ID Using a Function

As we mentioned above, many plugins will help you expose the page’s ID. But the truth is that we can still find the ID of a page, post, etc., without a plugin. The information is there. We need to know where to look.

The plugin I showed you earlier will add an ID column to the WordPress admin screen.

If you want to add the ID column to pages and posts by yourself, you can do that by using a custom function instead of installing a plugin.

The process is straightforward, and we initially need to add a couple of short functions to the manage_pages_columns and the manage_posts_columns filter hooks.

The functions will add a new column to the pages and posts managing screens and contain the unique ID numbers in them.

Both functions will need to be added to the bottom of the functions.php file of your child theme. We can access the file using FTP software or the file editor screen.

Note: please make sure to backup your website before editing core files.

To do that, navigate to Appearance -> Theme File Editor, and click on the functions.php file from the right sidebar.

Then, scroll to the bottom of the file and paste the code below:

add_filter( 'manage_pages_columns', 'revealid_add_id_column', 5 );
add_action( 'manage_pages_custom_column', 'revealid_id_column_content', 5, 2 );
add_filter( 'manage_posts_columns', 'revealid_add_id_column', 5 );
add_action( 'manage_posts_custom_column', 'revealid_id_column_content', 5, 2 );

function revealid_add_id_column( $columns ) {
   $columns['revealid_id'] = 'ID';
   return $columns;
}

function revealid_id_column_content( $column, $id ) {
  if( 'revealid_id' == $column ) {
    echo $id;
  }
}
Show page id with a WordPress function

Once pasted, save the changes and navigate back to the all pages screen to ensure the new ID column was added successfully.

Add page ID column

If you didn’t like any of the above methods or prefer to find the page ID without using a plugin or a function, move forward to the next section.

Find the ID in the URL

You may be surprised, but we don’t need to use a plugin or a function to find IDs in WordPress. We can find the ID of every page, post, or taxonomy inside their source code or the editor screen, and it’s pretty easy.

Using the View Page Source

One of my favorite ways to reveal the ID is that you don’t have to be logged in to your WordPress website. Working on custom functions on my local machine saves me extra time logging in and navigating to the page list.

To use the page source code method, navigate to the desired page, right-click anywhere on the page and click on View Page Source.

View Page Source Of a Page

Don’t be overwhelmed by the exposed page source code. It is a big one, but we only use it to find the page ID number.

Use your keyword to search by clicking on CTRL + F (Windows) or COMMAND + F (Mac) and search for id-. The number to the right of the search result is the ID.

View Page Source to find the ID

In the example above, the revealed post ID number is 105.

Find the ID From the Admin Screen

Another great way to expose any ID in WordPress is from within the list pages. Again, you can use it for posts, pages, custom post types, taxonomies, and media.

For example, if we want to get the ID of a page, we will navigate Pages -> All Pages.

Navigate to all pages

Then, hover your mouse on the edit option of the desired page. By hovering over it, the edit URL of that page will be exposed, and we can see the ID in the link on the bottom left side of the screen.

Hover on edit to expose the ID

The nice thing about this method is that we don’t need to click on the edit option. Hovering on it is enough and will do the trick.

Using this method saves valuable time if you need to get the IDs of multiple pages. You can quickly go through many pages without getting into the edit screen.

Inside the Page Editor Screen

If finding the ID using the method above didn’t work, you can still see the ID from inside the edit screen.

To do that, launch the edit screen of your desired page. Again, that will work with custom post types, categories, tags, and media.

Edit page to reveal ID

Then, inside the editor, look at the URL in your browser and look for post=. The digits following to the right are the page ID number.

Look for the ID in the edit page URL

In the example above, the page ID is 23.

Alternatively, if you are looking to find a category ID or tag ID, look for category&tag_ID= and post_tag&tag_ID= respectively.

Find category ID in the edit page URL

In the example above, the revealed category ID is 4.

Conclusion

This article taught you how to get a page ID number in WordPress, with or without a plugin.

If you need to find IDs often, using a plugin will save you a lot of time. But if you only need to find an ID once in a while, you can use the manual ways I showed you above.

Leave us a comment and tell us which of the above methods you used to achieve this task.

Also, make sure to subscribe to our YouTube channel and like our page on Facebook.

PluginsForWP

PluginsForWP is a website specializing in redistributing WordPress plugins and themes with a variety of knowledge about WordPress, internet marketing, and blogging.

Leave a Reply


Get notified about new content and coupon codes!

JOIN OUR COMMUNITY OF 120,000+ WORDPRESS ENTHUSIASTS