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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Luke Travis](https://secure.gravatar.com/avatar/fc5e21e1c8b13fcccac8db96ddde2d1a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Luke Travis
2,887 Points$handle parameter of wp_enqeue_style() function
I don't understand exactly what exactly the $handle parameter is in relation to the wp_enque_style() function. Is the handle parameter defining a handle for the stylesheet, or is it calling a preexisting handle that is defined somewhere else? Also, when using the get_template_directory_uri() as the src parameter, how does the get_template_directory_uri() know to grab from the css directory
3 Answers
![Chris Shaw](https://secure.gravatar.com/avatar/89a81f4cc3cec373f6a1547fde9e8c26?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Chris Shaw
26,676 PointsHi Luke,
The $handle
parameter is simply the name of script to want to queue, the name can be anything you want as it's simply a way for WordPress to track your script along the way so if you need to dequeue the script you can and change it to something else.
http://codex.wordpress.org/Function_Reference/wp_enqueue_style#Examples
![Luke Travis](https://secure.gravatar.com/avatar/fc5e21e1c8b13fcccac8db96ddde2d1a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Luke Travis
2,887 Pointsthanks for the response Chris. I guess my real question is, say I use the function wp_enqueue_style('main', get_template_directory_uri() . '/style.css'); If I had used wp_register_style('main', get_template_directory_uri() . '/style.css'), then I would have only needed to use one parameter when using the wp_enqueue_style() script. However, seeing as I never used wp_register_style before using wp_enqueue_style(), does the wp_enqueue_style() function do double duty of registering a stylesheet AND queueing it up?
![Chris Shaw](https://secure.gravatar.com/avatar/89a81f4cc3cec373f6a1547fde9e8c26?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Chris Shaw
26,676 PointsI think there is general confusion about what each function does, wp_register_style
simply lets WordPress know that the style path should be known within the backend code but no yet queued for the page whereas wp_enqueue_style
actually adds the style link to the page source.
In the nutshell.
wp_register_style
This allows you to name a custom style and it's path without queuing it for use on the page itself, when you register a style it's best practice to use
wp_deregister_style
to ensure that any plugins loading the same resource don't overwrite your style registration. Once the style is registered it sits in the backend waiting forwp_enqueue_style
to be called for the style$handle
.
wp_enqueue_style
This allows you to queue up a pre-registered style so that WordPress will output the link path to the page source, if you don't need the style to be loaded on a specific page you can use
wp_dequeue_style
which will remove the style$handle
from the backend queue and prevent it from appearing in the page source.
![Luke Travis](https://secure.gravatar.com/avatar/fc5e21e1c8b13fcccac8db96ddde2d1a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Luke Travis
2,887 Pointsthanks for the wise words chris!