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 WordPress Theme Development The WordPress Loop Adding the Loop to the index.php File

Registering scripts/stylesheets?

This occurred earlier in the tutorial but I forgot to ask! According to the codex you need to register scripts/stylesheets in order to enqueue them, but Zac does not do that in these videos.
What is the rationale here for it doing it w/o registering first?

i.e

wp_register_style( 'normalize_css', get_template_directory_uri() . '/css/normalize.css' ) ;    

wp_enqueue_style( 'normalize_css', get_template_directory_uri() . '/css/normalize.css' ) ;  

2 Answers

Thanks Sharon.
Maybe it went over my head, but what I got out of that link is that you have to register, but you don't need to enqueue right away....
While we're at it can you explain to me in a broad sense what registering and ensuing files actually does?

Tom Cox
Tom Cox
4,362 Points

Nijad,

I think it's akin to the difference between defining a function (saying what it's arguments are and what it ought to do) and calling the function. So, I can write a function in any language (PHP, JS, etc.), but the function doesn't have any effect on my program until I call it. Thus, the enqueuing is a helpful way to show you (or whoever else you're collaborating with) the assets that you are employing on your site, and the enqueuing allows you the flexibility of where and when to use it. Most people just load all their assets every time into the footer, but if your website is really big, that's impractical and will take up bandwidth and slow your user's experience down. So if you can register, then you have flexibility in what you enqueue and where with conditional statements.

So, basically, it's not necessary, but it is clear communication and gives you a bit more flexibility as to when your assets are deployed on certain pages. Also, it's the WordPress way, so it's a really helpful way to keep your code readable rather than idiosyncratic. Hope that helps!