There’s a part in your header template that’s already doing conditional loading:
<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
This code loads the JavaScript for comments into the queue; WordPress then loads all of the scripts when it fires the wp_head()
trigger.
My recommendation would be to use your functions.php
file to register the scripts, then use wp_enqueue_style()
to load them.
In functions.php
You’ll first need to register all of your scripts. Use code similar to this:
function my_load_styles() {
$template_uri = get_template_directory_uri();
wp_register_style( 'my-blog-page', $template_uri . '/styles/blog-page.css', '', '1.0' );
wp_register_style( 'my-gallery-page', $template_uri . '/styles/gallery-page.css', '', '1.0' );
}
add_action( 'init', 'my_load_styles' );
This will register all of your various stylesheets with WordPress. Then you can pick and choose which ones will be loaded.
In header.php
Just below the <?php if ( is_singular() ) ...
line, add the following:
<?php if ( is_page_template( 'blog-page.php' ) ) wp_enqueue_script( 'my-blog-page '); ?>
<?php if ( is_page_template( 'gallery-page.php' ) ) wp_enqueue_script( 'my-gallery-page '); ?>
If you’re using the page template identified in the conditional (remember to use the full page template file name), then WordPress will add that template’s stylesheet to the queue and echo it to the browser. No need to do it yourself.