Anyone know how I can get the post ID of the current page?
So, if I'm on a particular post, inside my header.php, I want to be able to get the current post id.
Thanks!
You can also find the post ID in the WordPress editor, which you get to by clicking on the post you want. When done this way, the post ID is in the address bar. The URL shown will be exactly the same, and the post ID is again sandwiched between the “post=” and the “&.”
A post ID is a unique number assigned to each post on a WordPress website. Each page also contains an identifying number, called a page ID. WordPress uses IDs to keep track of every piece of content within the WordPress database.
Bookmark this question. Show activity on this post. $page = get_page_by_path("page-slug", OBJECT, 'page');
Try using this:
$id = get_the_ID();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With