Current page id returns the incorrect value
To get the current page ID outside of The Loop, you need to use get_queried_object_id(); ($wp_query-> is unnecessary). However, this will only work when you are viewing a single Page (so anything under Pages > All Pages in the back-end). If you are viewing the blog, an archive, or a category it will not be … Read more