The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Get the ID of the current page (WordPress) Re: Get the ID of the current page (WordPress)


For people with the same issue of grabbing the post ID I wrote a better solution on my website: Access the current page id anywhere

Basically it involves storing the id in a global variable which you can then access anywhere you need. The global is set with a hook to wp_head by accessing the main page query. Read more on my website for the function.

The above use case would then look like this:

global $main_post_id;