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.
Try using this:
$id = get_the_ID();
In some cases, such as when you're outside The Loop, you may need to use get_queried_object_id() instead of get_the_ID().
$postID = get_queried_object_id();
Try:
$post = $wp_query->post;
Then pass the function:
$post->ID
You can get id through below Code...Its Simple and Fast
<?php $post_id = get_the_ID();
echo $post_id;
?>
you can use $post->ID for current id.
global $post;
echo $post->ID;