Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

ahmad abdolsaheb
ahmad abdolsaheb
16,985 Points

Problem with Adding Bootstrap CSS via the functions.php File

bootstrap.min.css is not added to the header.php; although I took the following steps:

  1. pasted the bootstrap.min.css in themes/bootstrap-to-wp/css 2.added the following to functions.php:

<?php function theme_styles() {

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

} add_action( 'wp_enqueue_scripts', 'theme_styles' ); ?>

3.added the following to header.php before </head> : <?php wp_head(); ?>

When I check the source-code after these steps, the bootstrap.min.css does not load with the rest of the header.

any help is appreciated.

3 Answers

Try this...

<?php
  function theme_styles() {
    wp_register_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap.min.css' );
    wp_enqueue_style( 'bootstrap_css' );
  }
  add_action( 'wp_enqueue_scripts', 'theme_styles' ); 
?>

Otherwise, I usually find it easier to include bootstrap's css without modifying functions.php...

Add this at the top of style.css before any code but after the stylesheet header (the comment):

@import url('css/bootstrap.min.css');

Please note that you may have to change this path to match your project.