Skip to content

WPShout Newsletter

Sign up for news, tips, and insights to help you build better websites.

Newsletter - Top banner

How to Find WordPress Post ID (No Code)

I’m going to cover two different no-code ways to get the ID of any post on a WordPress site you control. First, I’ll cover how to find the WordPress post ID with the web page’s HTML, then we’ll locate the numeric ID of the post by editing that post.

Option 1: Find a WordPress Post ID in the Page HTML

Here’s how to find the WordPress post ID of a WordPress site when you’re not even logged in.

  1. Navigate to the page of your WordPress site you’d like to determine the numeric page ID for.
  2. In your web browser, view the source of the webpage. The way I most-often do this is with a right-click on a empty part of the web page, and a click on “View Page Source” (or similar) in the contextual menu.
  3. When you’ve got a mish-mash of HTML from the page (most often opened in a new browser tab) before you, you’ll want to search that (most easily invoked with a CMD or CTRL+F keyboard shortcut) for the string “postid-“. Usually you’ll find attached to a body tag in a WordPress site that HTML/CSS class, and the numeric post ID. So it’ll look like postid-1234. That’s precisely your numeric post ID.
How WordPress post id looks in an example HTML tag
What WordPress post ID looks attached to a <body> HTML tag

👋 If you’re looking for an ID of a WordPress page, you should search for “page-id-“ instead of “postid-“.

Option 2: Find the WordPress Post ID by Editing the Post

This is probably the easiest way for most people. The only downside: you must be logged into the WordPress site. That’s kind of step-zero of this method of find the page ID. After that it’s pretty simple:

  1. Navigate to the page of your WordPress site you’d like to determine the numeric post ID for. (You should be logged in to WordPress in the browser window you’re doing this in.)
  2. Because you’re logged in, the “admin bar” should be showing across the top of your WordPress site. If it is, click “Edit Post.”
  3. On the resulting page, look at your web browser’s URL bar (you may need to click into that bar to see the important part). In the URL, you’ll see a segment that looks something like ?post=1234.  That 1234 (yours probably won’t be 1234 😛) is the numeric ID or post_id of this specific WordPress post.
WordPress post id in browser URL
What WordPress post ID looks in a web browser’s URL bar

Developer? Here’s the Answer You Might Have Been Seeking

If you’re happy with the above, the below is superfluous. But I can imagine a developer or two finding this page, wanting the WordPress PHP function to find the post ID.

If that’s you, the most-often-right answer is get_the_ID(). That relies on you being within the WordPress loop, but for most of the time I’m looking to do this as a WordPress developer, I am within the loop, or close enough for get_the_ID() to work.

Outside the Loop, you might want to use get_queried_object_id() for post ID retrieval.

Hope that’s helpful 🙂

Yay! 🎉 You made it to the end of the article!
David Hayes
Share:

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ranuka
November 22, 2019 4:46 am

If anyone looking to get WordPress post ID outside of the loop, you can use the following code.

global $post;
echo $post->ID;

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!