简体   繁体   中英

How do I include JQuery and Bootstrap.min.js in Wordpress?

This has been asked before but I am still struggling with understanding it.

I have wp_head() in my header.php file in the <HEAD> </HEAD> .

In my functions.php I have:

    <?php

function my_scripts_method() {
    wp_enqueue_script(
        'custom-script',
        get_template_directory_uri() . 'js/bootstrap.min.js',
        array( 'jquery' )
    );
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

?>

In js/ I have bootstrap.min.js and jquery-1.11.0.min.js.

The reason I know it isn't working is because I have a carousel in bootstrap which isn't running, as it requires bootstrap.min.js.

Many thanks!!!

You need a '/' before 'js', like

get_template_directory_uri() . '/js/bootstrap.min.js',

get_stylesheet_directory_uri() is the same way. These functions return a uri without a trailing slash.

Your js is loaded correctly. You should just make sure that it is in the js folder. Another point to take note of, if you are using a child theme, you should use get_stylesheet_directory_uri . For more info refer to the codex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM