2

Im new with using wordpress and im wondering if it is possible to install bootstrap to my twentyfourteen theme? Thanks!

9

The best way to include bootstrap in your theme is to enqueue bootstrap CSS and JS in your functions.php file.

This is how you can enqueue bootstrap CSS and JS from CDN hosted version.

function my_scripts_enqueue() {
    wp_register_script( 'bootstrap-js', '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js', array('jquery'), NULL, true );
    wp_register_style( 'bootstrap-css', '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css', false, NULL, 'all' );

    wp_enqueue_script( 'bootstrap-js' );
    wp_enqueue_style( 'bootstrap-css' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_enqueue' );

If you do not want to use CDN hosted version then download and put the bootstrap stuff in your theme, and include it like this.

function my_scripts_enqueue() {
    wp_register_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), NULL, true );
    wp_register_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css', false, NULL, 'all' );

    wp_enqueue_script( 'bootstrap-js' );
    wp_enqueue_style( 'bootstrap-css' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_enqueue' );
  • thank you Robert. Do i still need to include the bootstrap files inside my wordpress folder? – user3754764 Oct 2 '14 at 3:36
  • If you are using CDN hosted version (first code block) then you do not need to add anything else in your theme folder. I also would recommend you to use CDN version. – Robert hue Oct 2 '14 at 3:41

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.