0

I'm looking to load Bootstrap on a theme I'm working on though can't figure out how to add the JS file that comes with Bootstrap. I already created a function that loads some of my custom styles and it works great, afterwards I downloaded Bootstrap, moved the file into my theme directory and added

wp_enqueue_style('bootstrap', get_template_directory_uri() .       'css/bootstrap.min.css');

I haven't tried that so I don't know if it works or not, now I just have to add the bootstrap.min.js file but can't figure out how, so your help would be appreciated.

This is my code so far

<?php 

function xobamax_resources() {

    wp_enqueue_style('bootstrap', get_template_directory_uri() . 'css/bootstrap.min.css');
    wp_enqueue_style('style', get_stylesheet_uri());


}

add_action('wp_enqueue_scripts', 'xobamax_resources');

1 Answer 1

6

Here you go..

function xobamax_resources() {
    wp_enqueue_style('bootstrap', get_template_directory_uri() . 'css/bootstrap.min.css');
    wp_enqueue_style('style', get_stylesheet_uri());
    wp_enqueue_script( 'bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js', array('jquery'), '3.3.4', true );
}
add_action('wp_enqueue_scripts', 'xobamax_resources');

I have added the CDN version, You can replace that with your local copy. I want to suggest you to read more about wp_enqueue_script()

3
  • Bootstrap is a core-bundled script and you cannot submit a theme using a CDN. This is incorrect.
    – User
    Mar 8, 2017 at 16:36
  • 2
    @User Bro it's your own choice .. I can tell you how to cook dinner but not how to eat.. I hope you got my point. Mar 14, 2017 at 5:10
  • If you want the library's styles loaded before all other styles, and the theme's styles loaded after all others (with plugin's styles in the middle), you have to use two functions. The first one, with priority "9", will be used to load the library's styles, and the second one, with priority "10", will be used to load the theme's files. Using only one function to load everything, in a theme, results in a situation where the plugin's styles are the first ones to be loaded. Jul 2, 2021 at 17:31

Your Answer

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

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