When can you get current page ID and initialize hooks right after?

The earliest safe hook to get post information is the template_redirect hook. All the hooks in question runs before WordPress has setup postdata, so any post info are still unavailable at that point.

The globals like $wp_query and $post will still contain no data, that is why your efforts returns nothing.

EDIT

Extra info as per comment by @TheDeadMedic

Actually wp is an earlier, still-safe hook – just make sure to use get_queried_object() instead of relying on $post global

Leave a Comment