0

The below works great in loading a Javascript File into my theme (via a child theme)...

function my_scripts_method() {
        if ( is_page_template('templates/page-alert-amber.php')):
        wp_enqueue_script(
            'bootstrap js',
            get_stylesheet_directory_uri() . '/bootstrap/js/hellojs.js',
            array( 'jquery' )
        );
        endif;
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

My question is - how do I also include a style sheet? I thought the below would work but it doesn't...

function my_scripts_method() {
        if ( is_page_template('templates/page-alert-amber.php')):
        wp_enqueue_script(
            'bootstrap js',
            get_stylesheet_directory_uri() . '/bootstrap/js/hellojs.js',
            array('jquery')
        );
            wp_enqueue_style(
            'bootstrap css',
            get_stylesheet_directory_uri() . '/bootstrap/css/hello.css',
            array()
        endif;
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

thanks

0

Your issue is the dependency:

array( '' )

That's setting your stylesheet to have a dependency on a stylesheet whose name is an empty string. If you want to say that there's no dependency you need to use an empty array:

array()

Also, your second bit of code is missing an endif, which will cause a fatal error.

  • thanks but still no joy...I added the endif and your recommendation but it just crashes the site. There is something else missing here.... – henry Jul 17 '18 at 2:49
  • ^ i amended the code pls see my original question which I have edited above – henry Jul 17 '18 at 2:49
  • Now you're missing the closing ); from wp_enqueue_style()... – Jacob Peattie Jul 17 '18 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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