How to get Post ID or Page ID in WordPress

How to get Post ID or Page ID in WordPress

Get Post ID or Page ID in WordPress

WordPress users sometimes need post ID or page ID. It need when we have to do something specifically to that post or page. For example if you want to hide Ads in a selective page. There’s plugins available for this  purpose and they will ask for that page’s ID. Or another example is hiding title for post or page.

You can get the ID using three different methods. All methods are applicable for both posts and pages.

1. Get Post ID from URL

This one is very simple method. Just open the post or page in editor window. Now check the URL showing on the browser.  There will be the ID of that post. Check the below screen shot.

get post id from url in wordpress

In this the number underlined with red (359) is the post id.

2. Get Post ID from Source Code

In this method you have to open the source code of the post or page. For this right click on the page link and view source code (for some browsers there will be option as “inspect element”). You can find the post ID just above the class name. Check the below screen shot.

get page id from source code in wordpress

Did find this method little complicated and the first one easier ? Then why we needed this method? This method not just for getting Id’s. if you want to check any elements in your page or posts, you will need to check the source code. So for a blogger this method is always helpful.

3. Get Post ID using Plugin

The difficulty of the above two methods is that you have to open editor or source code each time to get the ID. There’s two best plugins available for this purpose. Both of them do the same thing. They will add an extra field on All Posts or pages with name “ID”. You can get each post’s or page’s ID from that field. You will also get ID’s of categories, links, comments, tags, users etc. So install any of the below plugins. There’s no settings needed for this plugin, just install and activate it.

  1. Reveal IDs

  2. Show IDs

Check the below screenshot. I have added Reveal Id’s plugin and it’s now showing post id for all posts.

get Post ID using plugin wordpress


Also Read:

M S Sujeesh

Leave a Reply

Your email address will not be published. Required fields are marked *