2

it is causing problem because i did not do it before. I am trying to enqueue style or may be scripts depending on page. But it not working. Here is the code:

add_action('init', 'my_enqueue_styles');

function my_enqueue_styles(){
    if(is_page('Add Event')){ // also tried slug, page id and wp_reset_query(); bot not worked

    wp_deregister_style( 'jquery-ui-custom-flick' );
    wp_register_style( 'jquery-ui-custom-flick', get_bloginfo('template_directory') .'/styles/jquery.ui/ui.custom.flick.css');
    wp_enqueue_style( 'jquery-ui-custom-flick' );
    }

}

I am not doing the conditional right. The script works without the conditional.

Thanks!

RESOLVED:

The problem was with the init action hook. the conditional is_page() is false when init is called. After adding the style to the hook wp_print_styles it worked perfectly.

1 Answer 1

3

It should work like this.

Sidenotes: I don't know why you deregister a stylesheet and register it again. Also: get_bloginfo('template_directory') is now replaced by get_template_directory_uri(). Third: Are your folders really named with dots in between? Maybe this causes problems. And maybe your ui stylesheet is an dependency of the main jquery ui stylesheet.

You should also start accepting answers on your questions. Your "accept rate" of 67% will people hold back from answering your Qs.

function wpse_16487_enqueue_styles()
{
    if ( is_page('Add Event') ) // also tried slug, page id and wp_reset_query(); bot not worked
    { 
        wp_register_style( 'jquery-ui-custom-flick', get_template_directory_uri().'/styles/jquery-ui/ui-custom-flick.css', 'jquery-ui' );
        wp_enqueue_style( 'jquery-ui-custom-flick' );
    }
}
add_action( 'wp_print_styles', 'wpse_16487_enqueue_styles' );

If something's not working, you should start debugging your wp query: echo '<pre>'; print_r($GLOBALS['wp_query']); echo '</pre>'; and check for the page name/slug to register it.

3
  • Thanks for the get_template_directory_uri(); tips :) and directory name with dot won't cause any problems. As i said the code works fine if i don't use the conditional is_page();. I guess is_page() is false when wordpress running the functions.php file. So the style not adding.
    – Sisir
    Commented May 6, 2011 at 8:38
  • 1
    Worked! The problem was with the init action hook. the conditional is false when init is called. After adding the style to wp_print_styles it worked perfectly. Thanks!
    – Sisir
    Commented May 6, 2011 at 9:04
  • Nice to hear. Gald it worked.
    – kaiser
    Commented May 6, 2011 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.