EDIT
The main reasons for registering scripts are as follow
- Makes it easier to call a script/style when we need it
- Makes it possible to use a registered script/style as a dependency for a file we need to load.
- Prevent ourselves to write the same code more than we need to, effectively simplifying our code
- More things that I might not be thinking of right now
NOTE
A script/style that has been registered doesn't need to be enqueued if it is listed as a $deps
of the file you are currently enqueuing.
An example (not necessarily how you should do it, but so you understand the purpose)
I have registered
- common-style.css
- navigation.css
- buttons.css
Now those style are registered, so if I go on a specific page and want to apply a different styling there. I enqueue on that page (either by conditional statement in functions.php or in my page template) specific-style.css
like so.
add_action( 'wp_enqueue_scripts', 'my_specific_style' );
function my_specific_style(){
wp_enqueue_style( 'specific-style', get_stylesheet_directory_uri() . '/path/to/specific-style.css', array( 'common-style', 'navigation', 'button') );
}
Note that the array in wp_enqueue_style
is a array of the handles of already registered styles. WP will conveniently load all 4 files in the correct order to respect dependency.
You could cascade dependency by simply registering each script/style with correct dependency
i.e buttons.css depends on navigation.css that depends on common-style.css
If I register with that logic in mind, I only need to enqueue specific-style.css with buttons.css as a dependency and WP will daisy chain the loading to respect the order.