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

Krusty Ruffle krustyruffle at rustykruffle.com
Thu Oct 30 04:30:51 GMT 2008


Hi! Thanks for the responses!

On Wed, 2008-10-29 at 21:17 -0500, Gaarai wrote:
> 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 );
>
>
> 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

I tried playing around with those, but I could not get it to work. After
reading this:

On Wed, Oct 29, 2008 at 10:25 PM, Callum Macdonald <lists.automattic.com@
callum-macdonald.com> wrote:

> I'm not sure why wp_print_styles() is not called automatically.


I searched through the source code, it seems that every instance that I can
find of wp_print_styles() being called is somewhere on the admin pages. My
guess is that it is left to theme authors to impliment it in their themes
so, I decided to try what Callum suggested with this:


>    add_action('wp_head', 'wp_print_styles');


embedded in the function. What I have now is the following:

 // Include a link to the current templates tweaks.css if it exists...
function krusty_plugstyles(){
    if (file_exists (get_template_directory()) . '/tweaks.css'){
        // register and enqueue our css for later addition into the head of
the page
        wp_register_style('krusted-plugstyles', get_bloginfo('template_url')
. '/tweaks.css', array(), '', 'screen');
        wp_enqueue_style('krusted-plugstyles');

        // since wp_print_styles() doesn't seem to run by default
        // we add a call to it with the wp_head action hook
        add_action('wp_head', 'wp_print_styles', '100');
    }
}

// add an action to call our function when wordpress starts loading a page
add_action('init', 'krusty_plugstyles');

This seems to be working, but now I'm left wondering if I should use a
conditional on it, maybe something like:

if ( !did_action( 'wp_print_styles'  )
     add_action ( 'wp_head, 'wp_print_styles', '100' );

or would that even be worth it?

Thanks for the help folks, I do appreciate it alot! :)


More information about the wp-hackers mailing list