The other answer confuses the function with the action hook. There is nothing wrong with using the wp_print_styles()
function to print a stylesheet link, as long as you've already registered/enqueued the stylesheet and know its handle.
(Fun fact: it's the function WP uses under the hood to output the enqueued stylesheets during wp_head()
.)
The guidance on the core blog and in the Trac ticket advises against using the wp_print_styles
hook to enqueue a stylesheet. In WP 3.3, this might have caused your custom stylesheet to load in the admin area, but this was fixed. Regardless, it's still the wrong hook for registering or enqueuing stylesheets, since it fires during the wp_print_styles()
function.
Generally, you should use wp_enqueue_style()
since it handles registration & enqueueing (and, as a result, printing the link as part of wp_head
). All-in-one simplicity.
However, if you need total control over where the stylesheet link is placed (say it needs to go in a specific template part, or wrapped inside <noscript>
tags), wp_print_styles()
is the right function to use.
Here's an example of how you might use them all:
// functions.php
function addMainStylesheet(){
wp_enqueue_style( 'main-styles', 'main.css' );
}
function registerNoscriptStylesheet(){
// registers the handle, but does not add it to the print queue.
wp_register_style( 'noscript-styles', 'noscript.css' );
}
add_action( 'wp_enqueue_scripts', 'addMainStylesheet' );
add_action( 'wp_enqueue_scripts', 'registerNoscriptStylesheet' );
// header.php
// Fire the `wp_head` hook, which prints the link for main.css
wp_head();
?>
<noscript>
<?php
// Now we'll print the handle we registered earlier
wp_print_styles( 'noscript-styles' );
?>
</noscript>
I'd recommend this question for more about the difference between wp_enqueue_style()
and wp_register_style()
:
Why wp_register_style() is important while I'm using a complete wp_enqueue_style()?
wp_prit_styles
we can tell you if you should change something or not.