-
Notifications
You must be signed in to change notification settings - Fork 2
Bootstrap Underscores
Adding Bootstrap to any given web site project is simple, while implementing it completely may take more substantial effort. Before we get started, let's look at the Underscores theme a bit more.
Though this is not the preferred way of adding CSS to your project, it is probably the easiest. For the sake of this example, we're going to use a CDN to provide Bootstrap, and we'll include the CSS file directly in the header.php template.
- In your file editor, open
header.php - Visit the Bootstrap Getting Started page and locate the Bootstrap CDN section near the top. http://getbootstrap.com/getting-started/#download
- Copy the top two link tags to your clipboard, so that you have something that looks like this:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">- In your file editor, open the
header.phpfile in our theme. - Locate the line with the following code
<?php wp_head(); ?> - Paste your code beneath that, on a new line.
- Save the file.
Refresh the page in your browser, and you might notice a slight change in font and shades of blue. Now that we have Bootstrap, let's use it in the theme.
Next, we'll use Bootstrap classes to make our sidebar work correctly.
header.php
- Open
header.phpand locate the #content div at the bottom. - Add the class
container-fluidto this div, so that the line reads:<div id="content" class="site-content container-fluid"> - Save the file.
index.php
- Open
index.phpand locate the #primary div near the top. - Add a new class to the #primary div named
col-sm-8. - Above that div, create a new div with the class
row. - Locate the
<?php get_sidebar(); ?>function at the bottom. - Beneath that line (above the
get_footer();line), close the .row div.
Your resulting code should look something like this:
<div class="row">
<div id="primary" class="content-area col-sm-8">
...
</div><!-- #primary -->
<?php get_sidebar(); ?>
</div><!-- closing .row -->
<?php get_footer(); ?>sidebar.php
- Open
sidebar.phpand locate the #secondary div. - Add the class
col-sm-4to this div and save the file.
Visit http://local.wordpress.dev to see your new responsive Bootstrap sidebar. Party down.
We made a great sidebar on the site's homepage in the previous section, but we have a few more template files to modify before we're done.
To make your sidebar work through your whole site, repeat the index.php section above for each of the following template files:
- archive.php - Template for lists of posts: categories, tags, and author page.
- page.php - Template for and individual Page.
- search.php - Template loaded when showing search results.
- single.php - Template for an individual Post.