[wp-hackers] requesting information about wp_*_style functions

Gaarai gaarai at gaarai.com
Thu Oct 30 02:17:53 GMT 2008

I think that doing both wp_enqueue_style and wp_print_styles 
back-to-back is a bit unnecessary. Here's some code that I ripped from 
wp-includes/general-template.php which shows how determining whether to 
enqueue or print is appropriate:

if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue.  Print this one immediately

    wp_print_styles( $handle );

else // Add to style queue

    wp_enqueue_style( $handle );

Since you are using the function on a wp_head action, you might as well 
just forget about queuing it since the queue won't be used any longer. 
Of course, you could always latch into the "admin_print_styles" or 
"wp_print_styles" actions as appropriate and enqueue your stylesheet 
rather than calling the wp_print_styles function directly.

- Chris Jean

Krusty Ruffle wrote:
> I want to be able to write a file called tweaks.css, place it any theme's
> directory and use it to tweak styles for plugins that don't match the theme
> very well, or for minor theme tweaks to the theme itself. To be able to
> overwrite the styles that are loaded by other things I need it to be linked
> last in the pages head.
> This is the code that I've come up with for this. It seems to work, but I
> feel like this is not quite right. Could somebody let me know if I've done
> this right and maybe send me a link or explain the proper way to do this?
> Thanks in advance for any help with this, it is greatly appreciated. :)
> // Include a link to tweaks.css if it exists in the current templates
> directory...
> function krusty_plugstyles(){
>     if(file_exists(get_template_directory()) . '/tweaks.css'){
>         wp_register_style('krusted-plugstyles', get_bloginfo('template_url')
> . '/tweaks.css', array(), '', 'screen');
>         wp_enqueue_style('krusted-plugstyles');
>         wp_print_styles('krusted-plugstyles');
>     }
> }
> // add an action when wordpress loads a pages 'head', use '100' in hopes
> that this will be the last thing to run.
> add_action('wp_head', 'krusty_plugstyles', '100');
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list