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

1 Answer 1

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.

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

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.