Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
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 May 6 '11 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 May 6 '11 at 9:04
    
Nice to hear. Gald it worked. –  kaiser May 6 '11 at 13:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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