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)
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.