I am trying to understand how wordpress works, but I am having issue understanding how wp_enqueue_style(), wp_enqueue_script() works in relation to page output.

From my understanding, these functions do not output anything to the page until the template have been loaded because the template might want to register a style/script.

Going through wordpress themes files, I've noticed that most of them use echo statements. So, how does wordpress manage styles, when a particular template might register a style at the end of the theme. Remember that, css styles are always at the top, so logically wp_enqueue_style should have been called or am I the one being illogical?

1 Answer 1


Scripts and styles get output with wp_head and wp_footer functions. If you enqueue a style after wp_head, it will be output in wp_footer, which, while in practice will often work, means the theme's html will not validate. It's up to you (or whomever is building a theme/plugin) to enqueue styles early enough to be output in the head. All the data you'd need to determine if a style needs to be enqueued within the template is available before the template renders, so there's no reason why you can't enqueue everything before wp_head.

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.