Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If this works (and it's the way people do in a bunch of themes around the web):

<html>
<head>
    <!-- stuff -->
    <?php wp_enqueue_script('jquery'); ?>
    <?php wp_head(); ?>
</head>
<!-- more stuff -->

Why is it recommended to use a hook to enqueue scripts?

add_action('wp_enqueue_scripts', 'my_enqueue_scripts');
function my_enqueue_scripts() {
    wp_enqueue_script('jquery');
}
share|improve this question

1 Answer 1

Enqueue mechanics and suggested ways to use them serve flexibility and interoperability. Simply put consider what would be the easiest way for third party code to modify mechanics of yours?

Hardcoding things in template often makes editing that template the only viable option. Manipulating hooks is typically more convenient and less problematic than that.

On larger scale there are different opinions and approaches on balance of things between templates and hooks, however enqueue is strongly recommended to be used via hooks in all cases.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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