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 trialNijad Kifayeh
6,092 PointsRegistering 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
Sharon Jeter
9,965 PointsThis link explains it very well ... http://wordpress.stackexchange.com/questions/82490/when-should-i-use-wp-register-script-with-wp-enqueue-script-vs-just-wp-enque
Tom Cox
4,362 PointsNijad,
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!
Nijad Kifayeh
6,092 PointsNijad Kifayeh
6,092 PointsThanks 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?