Wordpress - How to get current page ID outside the loop?
Try
global $post;
echo $post->ID;
or (I don't know the difference)
global $wp_query;
echo $wp_query->post->ID;
You can simply do,
$page_id = get_queried_object_id();
Try
global $post;
echo $post->ID;
or (I don't know the difference)
global $wp_query;
echo $wp_query->post->ID;
You can simply do,
$page_id = get_queried_object_id();