5

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?

2 Answers 2

9

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.

2
0

the $wp global object is initialized in wp-class.php,

I just read an article that explains the wp init process,

I think the global $post variale gets defined and can be called after wp-setting.php...

let me know, regards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.