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 trialGlenn Basgaard
7,987 Pointsglobal $wp_scripts
Can anybody further explain what global
and $wp_scripts
individually pertain to. I couldn't find much on it. I did find that global $wp_scripts
is part of the source code for the wp_scripts()
function but that's about it. Thanks!
Michael Hazani
1,043 PointsMichael Hazani
1,043 PointsHi Glenn,
global isn't wordpress-related - it's simply a php keyword that denotes declaration of a global variable. More info here: http://php.net/manual/en/language.variables.scope.php (It's probably covered in Treehouse's PHP courses and is definitely covered in codecademy's intro to PHP.)
As far as I can tell, wp_scripts is an object that contains all the scripts your theme is using. Under the hood, that's where all the scripts you're registering are "kept", if you will. We initialize it globally before registering scripts in it, which is pretty straightforward, especially if you think of it in terms of OOP.
Interestingly, wp_scripts is also a function (https://developer.wordpress.org/reference/functions/wp_scripts/), which also initializes a $wp_scripts object - honestly I'm not sure what's the difference between the two ways of initializing.
If you want to dig deeper, here is a list of all the functions available through wp-includes/functions.wp-scripts.php - many of which are discussed in this lesson: https://developer.wordpress.org/reference/files/wp-includes/functions-wp-scripts.php/
Hope this helps!