Usually when people think of the global $post
object it’s assumed that it’s actually set whenever you enter The Loop. I started to play around with how early I could actually call global $post
which looks like:
before wp_head()
in most header.php
files
before template_redirect
action
after plugins_loaded
So my question is, what’s the earliest I have access to global $post
?
Global $post
var is set by WP::register_globals()
method.
It is called by WP::main()
method, on its turn called by wp()
function that is called when wp-blog-header.php
is loaded.
If you look at the graph @Rarst built, on the left, you can see where wp()
function is called.
In terms of hooks, global post variable is set just before "wp"
hook runs, so that is first hook to be safely used to check it.