Title: Help using wp_script_is() to conditionally load styles
Last modified: August 21, 2016

---

# Help using wp_script_is() to conditionally load styles

 *  [jlamerto](https://wordpress.org/support/users/jlamerto/)
 * (@jlamerto)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/help-using-wp_script_is-to-conditionally-load-styles/)
 * Hi,
 * I’m trying to load a style file if a particular script is enqueued. My approach
   has been to test if the script is enqueued and if so enqueue the supportive css
   file. But the `<link rel='stylesheet' id='init-style-css' ...` is not in the 
   head. Any ideas why?
 * eg:
 *     ```
       function load_my_scripts() {
       	wp_register_script(
       		'init',
       		get_template_directory_uri() . '/assets/scripts/init.js',
       		false,
       		'1.0',
       		true
       		);
   
       	wp_register_style(
       		'init-style',
       		get_template_directory_uri() . '/assets/init-style.css',
       		false,
       		'0.1',
       		'all'
       		);
   
       	if ( is_home() ) {
       		wp_enqueue_script( 'init' );
       	}
   
       	if ( wp_script_is( 'init', 'enqueued' ) )
       		wp_enqueue_style( 'init-style' );
       }
       add_action( 'wp_enqueue_scripts', 'load_my_scripts' );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Birgir Erlendsson (birgire)](https://wordpress.org/support/users/birgire/)
 * (@birgire)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/help-using-wp_script_is-to-conditionally-load-styles/#post-4970036)
 * Can you see if the script is loaded on your home page (is_home)?
 * _edit_: I just tested your snippet and it works fine for me.
 * So I wonder if this is a `is_home` vs `is_front_page` case?
 *  Thread Starter [jlamerto](https://wordpress.org/support/users/jlamerto/)
 * (@jlamerto)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/help-using-wp_script_is-to-conditionally-load-styles/#post-4970093)
 * Hmm… I can confirm that the enqueue script is being loaded just the style that
   ain’t.
 * The problem seems to be the `if ( wp_script_is( 'init', 'enqueued' ) )` which
   returns false.
 * Changing it to:
    `if ( ! wp_script_is( 'init', 'enqueued' ) )`
 * Give the correct result. But that makes me worry because it shouldn’t.
 *  [Birgir Erlendsson (birgire)](https://wordpress.org/support/users/birgire/)
 * (@birgire)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/help-using-wp_script_is-to-conditionally-load-styles/#post-4970240)
 * Did you test it on the default theme?
 * Does this work for you:
 *     ```
       if ( is_home() ) {
       	wp_enqueue_script( 'init' );
       	wp_enqueue_style( 'init-style' );
       }
       ```
   
 * Sorry to ask, but you’re sure you aren’t enqueuing the init script somewhere 
   else?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Help using wp_script_is() to conditionally load styles’ is closed to 
new replies.

## Tags

 * [enqueue](https://wordpress.org/support/topic-tag/enqueue/)
 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)
 * [wp_enqueue_style()](https://wordpress.org/support/topic-tag/wp_enqueue_style/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Birgir Erlendsson (birgire)](https://wordpress.org/support/users/birgire/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/help-using-wp_script_is-to-conditionally-load-styles/#post-4970240)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
