Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Why enqueue/register stylesheets/scripts?

Why not just list them in header.php as we would do normally?
In the same vein, why not do the same for scripts and add them to footer.php?

1 Answer

Because you run the risk of having conflicts, and unless you're coding in if/else statements, you're probably loading all scripts/styles on every page, even when you don't need to.

Particularly these days with so many frameworks, plugins, etc. you don't want to be trying to load jQuery multiple times or in multiple namespaces, etc. Some scripts also have dependencies that you want to make sure are properly loaded.

So, simply put, enqueue/register allows more control, and is generally considered the 'right' way to do scripts and stylesheets.

Some articles on the matter: