Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tulanght/6c930b243f31fbfd2bdc to your computer and use it in GitHub Desktop.
Save tulanght/6c930b243f31fbfd2bdc to your computer and use it in GitHub Desktop.
Modern WordPress Theme Development

Development Software

  • VirtualBox - Virtualization software for running local operating systems within your computer. This allows us have a full version of linux within our computers that better match how a live webserver works.
  • Vagrant - A tool for provisioning (creating) virtual machines.
  • VVV - A pre-built, community-supported Vagrant configuration for WordPress development.
  • Git - Version control system for managing code during development. Easily allows for tracking changes, and merging new code into an existing project.
  • SourceTree - A GUI available on Windows and Mac for managing Git projects. This makes Git much easier to use, as we won't have to learn the command line interface.
  • Github.com - A website that provides free Git repositories for both open source and private projects.
  • SASS - (SCSS) A CSS preprocessing implementation that allows us to write much less CSS for a project. This basically makes CSS into a simple programming language.

WordPress Theme Build

  • _s - (Underscores) is a very simple WordPress starter-theme. Perfect for creating a brand new theme from scratch as it is completely unopinionated in its structure, and adheres to WordPress best practices out of the box.
  • Bootstrap - A CSS framework for easily making great responsive websites.

Install Required Software

  1. Download and install VirtualBox https://www.virtualbox.org/wiki/Downloads (I think we're safe to use the 5.x version)
  2. Download and install Vagrant http://www.vagrantup.com/downloads.html
  3. Download VVV 1.2.0 and unzip it to the folder where it will live. Rename the folder VVV (instead of VVV-1.2.0). https://github.com/Varying-Vagrant-Vagrants/VVV/tree/1.2.0
  4. Download and install SourceTree https://www.sourcetreeapp.com/ This is a Git GUI that I like a lot.

Install the VM and test

  1. Open a command prompt and go to the directory where you extracted VVV
  2. Type vagrant plugin install vagrant-hostsupdater, this will install a vagrant plugin that saves us a little work.
  3. Then type vagrant up, and go get some coffee, or have dinner or something... it can take 30 mins or so to install the virtual machine. (could be faster, so you could watch it work if you want)
  4. Once it is done, you should be able to open a browser and go to http://local.wordpress.dev to see your new local development version of WordPress
  5. You can login at: http://local.wordpress.dev/wp-login.php with admin and password

About Vagrant

Vagrant is a tool that helps provision (create/launch/make) development environments in a standardized manner. Using this, we can all easily have the exact same setup with very little effort.

Common/Useful Commands:

  • vagrant up - Start the virtual machine
  • vagrant halt - Stop the virtual machine
  • vagrant reload - Reboot the virtual machine
  • vagrant destroy - Delete the virtual machine

General usage reasons:

  • vagrant up - You are ready to start working on a project. In your command prompt (Terminal on Macs), browse to the directory where you extracted VVV and run vagrant up.
  • vagrant halt - You are done working for the day, or need to restart your computer for some reason. In your command prompt, browse to the directory where you extracted VVV and run vagrant halt.
  • vagrant reload - Something is acting strange in your development environment, or you can't access your local sites. In your command prompt, browse to the directory where you extracted VVV and run vagrant reload.
  • vagrant destroy - We'll probably never use this. If you need to completely start over with your development environment because something has gone terribly wrong.

Creating Themes with Underscores

To start, let's make a very simple Underscores theme that does not use SASS. This will allow us to gain a better understanding of a WordPress themes in general before getting involved with the other tools.

My First Underscores Theme

For this example, we're going to create a theme named "Awesomesauce".

  1. Visit Underscores' website http://underscores.me/ and find the text box named "Theme Name" next to a button named "Generate".
  2. In the Theme Name box, type Awesomesauce, then click Generate. This will download your newly generated theme as a zip file.
  3. Extract the zip file to your desktop for now.

We have created a new theme! Next, let's take a step back and explore the VVV WordPress files a bit, so we know where to put our new theme.

Exploring VVV

  • Using your computer's file manager (Explorer / Finder), browse to where you extracted VVV.
  • In the VVV folder, you'll see about a dozen files and folders. The only one we'll ever worry about is www. Open the www folder.
  • Now in VVV\www we have another few folders. For this series the only one we're going to work with is wordpress-default. Open the wordpress-default folder.
  • This is the folder we're going to work in: VVV\www\wordpress-default.

Next, let's take a quick look at the WordPress file structure.

Exploring WordPress

  • In the root of the WordPress folder there are 3 main directories, and about a dozen files.
  • The only file we'll ever worry about here is wp-config.php. But, since VVV set this up for us, we can ignore it all for now.
  • The only folder we'll concern ourselves with is the wp-content folder. This folder is where WordPress keeps plugins, themes, and file uploads. Go into the wp-content folder.
  • Go into the themes folder.
  • Now you should be at: VVV\www\wordpress-default\wp-content\themes. This is where we will put our newly generated theme.

Installing Your New Theme

  • Copy your newly extracted theme named awesomesauce into this folder, so that the index.php file for your theme can be found at this path: VVV\www\wordpress-default\wp-content\themes\awesomesauce\index.php
  • Login to WordPress at http://local.wordpress.dev/wp-login.php with the credentials admin and password.
  • In the dashboard visit Appearance, and you should see the Awesomesauce theme. Activate it.

You now have a working WordPress theme! No one said it was going to be pretty. In fact, quite the opposite. This is a completely blank theme, so it should have no style at all.

Spend some time exploring the theme files a little bit. Specifically, open style.css and look at the comments at the very top. These comments control the information about the theme itself.

/*
Theme Name: Awesomesauce
Theme URI: http://underscores.me/
Author: Underscores.me
Author URI: http://underscores.me/
Description: Description

If you change the Theme Name or Description here, it will change the name in the WordPress Appearance section.

Adding Bootstrap to Awesomesauce

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.

WordPress Theme Structure At A Glance

Fundamental files

  • style.css - This file serves double duty in a WordPress theme, and is automatically loaded for any activated theme.
    • At the top of the file, meta data about the theme is placed within a CSS Comment.
    • Beneath the theme meta data is the CSS styles for the theme.
  • index.php - The default template file used when no more appropriate template is found.
  • page.php - The template file for an individual Page.
  • single.php - The template file for an individual Post.

Additional files

  • header.php - The top-most HTML for a template file.
  • sidebar.php - The default template for sidebars.
  • footer.php - The bottom-most HTML for a template file.

How Templates Work

WordPress decides what template to use by the context of the webpage a user is viewing. For example when viewing a Page, WordPress will first look for a very specifically named template for the Page being viewed, then it will fallback to less specific template name until it finds the best match.

This can be a bit daunting at first, but luckily there is a lot of great information out there about this. The process of WordPress deciding what template to use is called the Template Hierarchy. For future reference, bookmark or download this file: https://developer.wordpress.org/files/2014/10/template-hierarchy.png

Examples Of Templates

Let's see how our Awesomesauce theme files work.

If we were to view an individual Post on the website, the theme files would load in the following order.

  1. single.php - Determined by WordPress to be the best match for the webpage being viewed.
  2. header.php - Loaded by single.php with the get_header(); function.
  3. template-parts/content-single.php - Loaded by single.php with the get_template_part( 'template-parts/content', 'single' ); function.
  4. sidebar.php - Loaded by single.php with the get_sidebar(); function.
  5. footer.php - Loaded by single.php with the get_footer(); function.

Adding Bootstrap

Though this is not the most-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.

  1. In your file editor, open header.php
  2. Visit the Bootstrap Getting Started page and locate the Bootstrap CDN section near the top. http://getbootstrap.com/getting-started/#download
  3. 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">
  1. In your file editor, open the header.php file in our theme.
  2. Locate the line with the following code <?php wp_head(); ?>
  3. Paste your code beneath that, on a new line.
  4. 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.

Using Bootstrap's Grid System

Next, we'll use Bootstrap classes to make our sidebar work correctly.

header.php

  1. Open header.php and locate the #content div at the bottom.
  2. Add the class container-fluid to this div, and save the file.

index.php

  1. Open index.php and locate the #primary div near the top.
  2. Add a new class to the #primary div named col-sm-8.
  3. Above that div, create a new div with the class row.
  4. Locate the <?php get_sidebar(); ?> function at the bottom.
  5. 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

  1. Open sidebar.php and locate the #secondary div.
  2. Add the class col-sm-4 to this div and save the file.

Visit http://local.wordpress.dev to see your new responsive Bootstrap sidebar. Party down.

Wrap-up

We made a great sidebar to the site's homepage in the previous section, but we have a few more template files to apply changes to 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 post types, categories and tags.
  • page.php - Template for and individual Page.
  • search.php - Template loaded when showing search results.
  • single.php - Template for an individual Post.

Adding Test Content

Rather than embarking on an incredibly tedious quest of writing a lot of fake content for our development site, we're going to import some. The WordPress Theme Unit Test is a collection of content created to help test your theme: https://codex.wordpress.org/Theme_Unit_Test

To install it on your site, follow these steps:

  1. Visit this page: https://codex.wordpress.org/Theme_Unit_Test
  2. Locate "Download test data" and save the given link to your desktop. (file as of this writing: https://wpcom-themes.svn.automattic.com/demo/theme-unit-test-data.xml)
  3. Log into WordPress, and on your dashboard visit Tools >> Import.
  4. Click "WordPress" at the bottom. Click Install Now.
  5. After the plugin is installed click "Activate & Run Importer".
  6. Upload and Import the test data file.

When the test data is completely imported, you should see an "All done!" message. Visit your site to find a whole lot of test content of every variety.

We're now done with the WordPress Importer plugin, so let's disable it.

  1. Visit your Dashboard >> Plugins
  2. Locate WordPress Importer and click the "Deactivate" link beneath it.

HTML, CSS, and Bootstrap Primer

To best understand Bootstrap, we need to make sure we are on the same page with HTML and CSS.

HTML

HTML is easy, it is simply a document that is interpreted by your browser. The same way MS Word "interprets" your .doc files, your browser interprets .html files.

When you view a websites' source code, you are viewing the raw HTML document.

Elements & Attributes

Elements, sometimes called "tags", are the individual components that make up the HTML document.

Some common elements are:

  • <div>
  • <h1>
  • <p>
  • <strong>
  • <img>

Some elements are meant to be containers for content and must be closed, while others are not meant to contain content and do not. Sometimes the latter type of element is called a "self-closing" element or tag.

Container elements:

  • <div>...</div>
  • <h1>My Page Title</h1>
  • <span>Some content.</span>

Self-closing elements:

  • <img>
  • <hr>
  • <br>

Elements can have attributes. Attributes are written as key-value pairs within the element's opening tag. The value for an attribute should alway be wrapped in quotation marks.

  • <div id="page-wrapper"></div> - "id" is the attribute, and its value is "page-wrapper"
  • <img src="some.gif" alt="a cat falls down"> - "src" is an attribute with the value of "some.gif". "alt" is an attribute with the value of "a cat falls down".

The class attribute is a little special in that it is actually a collection of values, with each value separated by a space.

  • <div class="one two three"></div> - "class" is an attribute, and it has three values: "one", "two" and "three".

CSS

CSS is a way to add style to your HTML document. We use it for things like: changing fonts, background colors and element layout.

We can target specific HTML elements in a number of ways, but the following methods are the most common.

Assume:

<div id="page-wrapper" class="one two"></div>
  • By element itself: div { border: 1px solid blue; }
  • By element id attribute: #page-wrapper { background: red; }
  • By element class attribute values: .one {} .two{}

To target an element by id we prefix it with a pound (hash) symbol: #elementID {}. To target an element by class we use a period in front of the class name .className {}.

Note: When you write CSS, you are applying the style to everything that matches your target statement. Meaning div { background: red } will cause every div element in the document to have a red background.

Bootstrap is a CSS Framework

Generally speaking, a framework is a set of common functionality shared by developers. Frameworks come in many shapes and sizes but serve a common purpose. They allow us to write less code and benefit from others' experience.

Some of the common functionality for websites that the Bootstrap framework provides are:

  • Responsive Grid
  • Responsive Navigation
  • Styled
    • Typography
    • Forms
    • Tables
    • Buttons
    • Images
  • etc.

And it is all cross-browser compatible.

Using Bootstrap

Starting with a very-simple HTML document, we're going to convert it into a Bootstrap styled page using only HTML.

This will be the starting document:

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
</head>
<body>

</body>
</html>

This is the goal:

--------------------------------------
|              Header                |
--------------------------------------
|           |            |           |
|   img     |    img     |    img    | 
|           |            |           |
--------------------------------------
| Page Title             | Sidebar   |
|                        |           |
| Content                |           |
|                        |           |
--------------------------------------
|              Footer                |
--------------------------------------

Here goes--

Create container and rows.

The first thing we need to do is provide the HTML and Bootstrap classes that the grid system provides for responsive layout.

  1. Using the container class, using define our top-level element.
  2. Within the container, we create a row for each major horizontal areas.
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
</head>
<body>

<!-- Container for rows -->
<div class="container">

	<!-- Header -->
	<header></header>
	
	<!-- Image row -->
	<div class="row"></div>
	
	<!-- Main -->
	<div class="row"></div>
	
	<!-- Footer -->
	<footer></footer>
</div>

</body>
</html>

Adding Columns

Bootstrap's grid system is based on a total number of 12 small columns. We can add multiple these 12 columns together to make a bigger column.

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
</head>
<body>

<!-- Container for rows -->
<div class="container">

	<!-- Header -->
	<header></header>
	
	<!-- Image row -->
	<div class="row">
		<div class="col-md-4"></div>
		<div class="col-md-4"></div>
		<div class="col-md-4"></div>
	</div>
	
	<!-- Main -->
	<div class="row">
		<div class="col-md-8"></div>
		<div class="col-md-4"></div>
	</div>
	
	<!-- Footer -->
	<footer></footer>
</div>

</body>
</html>

What did we do there?

The col-md-* bootstrap class means, "this div should take up * columns on screensizes medium and up".

Okay, but what does That mean?

By default, Bootstrap has 4 responsive breakpoints. We can take advantage of those breakpoints by using the desired column classes.

Column classes:

  • col-xs-* - extra small
  • col-sm-* - small
  • col-md-* - medium
  • col-lg-* - large and up

The asterisk * is how many of Bootstrap's columns this element should take up.

Let's look at each row we created individually:

Both the header and the footer take up the entire width of the container, so we do not need to use any special Bootstrap classes. But do notice that these elements are within the container div.

	<!-- Header -->
	<header></header>

...

	<!-- Footer -->
	<footer></footer>

The row of images is divided into three equal sections. Since Bootstrap works on a twelve column layout, our sections need to be 4 Bootstrap columns wide.

12 / 3 = 4

	<!-- Image row -->
	<div class="row">
		<div class="col-md-4"></div>
		<div class="col-md-4"></div>
		<div class="col-md-4"></div>
	</div>

The main content area is divided into two sections. The sidebar section is 1/3rd of the container width, and the content section is 2/3rds of the container.

Sidebar: 12 * 1/3 = 4 Content: 12 * 2/3 = 8

	<!-- Main -->
	<div class="row">
		<div class="col-md-8"></div>
		<div class="col-md-4"></div>
	</div>

In two previous sections rows and columns, we used the medium Bootstrap classes, like col-md-*. This means that any screen size equal to or wider than the medium breakpoint will see these sections as columns. While any screen smaller than the medium breakpoint will see only rows.

How this code looks on a small screen:

-------------
|  Header   |
-------------
|           |
|   img     |
|           |
-------------
|           |
|   img     |
|           |
-------------
|           |
|   img     |
|           |
-------------
| Page Title|
|           |
| Content   |
|           |
-------------
|  Sidebar  |
|           |
-------------
|  Footer   |
-------------

Default Bootstrap Breakpoints

  • <768px - Extra small devices (Phones)
  • ≥768px - Small devices (Tablets)
  • ≥992px - Medium devices (Desktops)
  • ≥1200px - Large devices (Desktops)

One more time with content

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
</head>
<body>

<!-- Container for rows -->
<div class="container">

	<!-- Header -->
	<header>
		<a href="/">Awesome Website</a>
	</header>
	
	<!-- Image row -->
	<div class="row">
		<div class="col-md-4">
			<img src="awesome-1.jpeg">
		</div>
		<div class="col-md-4">
			<img src="awesome-2.jpeg">
		</div>
		<div class="col-md-4">
			<img src="awesome-3.jpeg">
		</div>
	</div>
	
	<!-- Main -->
	<div class="row">
		<div class="col-md-8">
			<h1>This is my homepage. Marvel.</h1>
			<p>Welcome to my webzone.</p>
		</div>
		<div class="col-md-4">
			<h2>This is my sidebar</h2>
			<p>Here is where I put useful links or something.</p>
		</div>
	</div>
	
	<!-- Footer -->
	<footer></footer>
</div>

</body>
</html>

We've just made our first Bootstrap page. It is completely responsive, and we only used HTML.

Continued Reading...

Creating a Bootstrap Navbar in WordPress

Bootstrap offers a great component for responsive websites called a "navbar". Navbars are basically your site's header. You can include dropdown-ready responsive menus, inline search forms, or anything you want.

For more information on navbars, see the Navbar Documentation.

Menu Setup

By default Underscores provides a menu for this theme named "Primary Menu", as well as a default menu theme location named "Primary Menu". This is a little confusing, but don't let it worry you too much. Once we setup the menu to work correctly we'll never worry about it again.

Before we get to styling the header, we need to ensure that the primary menu is setup in WordPress.

To do this, let's login to the admin dashboard and go to Appearance >> Menus.

Make sure your primary menu is selected, then scroll to the bottom of the page and check the box that says Theme Location:[ ] Primary Menu. Save the menu.

This setting tells WordPress that this menu will appear in the "Primary Menu" theme location.

Note: While editing the Primary Menu, if you've installed the Theme Unit Test the "Home" link will be setup to go to an external website. Edit that link and change the url to /. This will make it into a real Home link for your own site.

Styling WordPress Menus

WordPress menus present a few challenges when trying to style them. By default, they come with their own set of CSS ids and classes. These CSS ids and classes created when the menu is rendered by what is called a "Nav Walker". Nav walkers are PHP classes that handle recursive output of a menu's HTML.

Basically, it can be really hard to give a menu the HTML you want. And since we're using Bootstrap, we need to have a significant amount of control over the HTML.

Adding a Bootstrap Nav Walker

Enter the Bootstrap Nav Walker class created by Edward McIntyre. This PHP class is a utility for making your WordPress menus render with Bootstrap HTML.

The first thing we need to do is to include this class in our theme.

  1. Open the above link and in the right column click "Download Zip".
  2. Extract that zip file to your desktop and locate the file named wp_bootstrap_navwalker.php.
  3. Copy the wp_bootstrap_navwalker.php file to the inc folder within your theme.
  4. Open the functions.php file in your theme, and find a line that starts with: wp_enqueue_script( 'awesomesauce-navigation' ... and delete that line of code completely.
  5. Open the js folder in your theme and delete the file named navigation.js.
  6. This javascript file is provided by Underscores to make your menus responsive, but since we are going to use Bootstrap for that functionality we no longer need it.
  7. Scroll to the very bottom of the file and add the following code on a new line, then save the file.
/**
 * Load the menu nav walker for bootstrap by Edward McIntyre
 * https://github.com/twittem/wp-bootstrap-navwalker
 */
require get_template_directory() . '/inc/wp_bootstrap_navwalker.php';

The above code tells WordPress to always load our new Bootstrap Nav Walker PHP class. But loading the file won't do anything on its own, we have to use it.

Modifying header.php

Now we're going to do some significant edits to the header to make it into a navbar.

  1. Locate the line that starts with <header id="masthead" ...
  2. Delete that line, and everything in the file that follows it. (yes, everything)
  3. Copy the following code, paste it at the bottom of the file (essentially replacing everything you just deleted), then save the file.
	<nav class="navbar navbar-default">
		<div class="container-fluid">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#primary-navigation" aria-expanded="false">
					<span class="sr-only">Toggle navigation</span>
					<small class="text-muted">Menu</small>
				</button>
				<a class="navbar-brand" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
			</div>
			<?php 
				wp_nav_menu( array(
					'menu'              => 'primary',
					'theme_location'    => 'primary',
					'depth'             => 2,
					'container'         => 'div',
					'container_class'   => 'collapse navbar-collapse',
					'container_id'      => 'primary-navigation',
					'menu_class'        => 'nav navbar-nav',
					'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
					'walker'            => new wp_bootstrap_navwalker()
				) ); 
			?>
		</div><!-- /.container-fluid -->
	</nav>

	<div id="content" class="site-content container-fluid">

Visit your WordPress site, and you should have a new fancy responsive header with responsive dropdown menus. Huzzah!

The above code is fairly simple, but let's go through it.

  • Most of the HTML above was copied from the Bootstrap Navbar example in their documentation. There is no shame in doing so, that is why it is there.
  • For the site name (branding), we've used the WordPress home_url() and bloginfo() functions.
  • So that our menu items work dynamically (i.e not hard-coded HTML), we have used the wp_nav_menu() function and provided it some Bootstrap related arguments.

Note: Instead of the normal "Hamburger" style menu that the example provides, we've used the actual word "Menu" for the button. Research shows that using the word "Menu" provides a better user experience than using a vague symbol. At the end of the day this comes down to personal preference or design specifications.

wp_nav_walker() and Arguments

There is no need to memorize how this function works, or what arguments it takes, but let's explore its use some more so that we know what is going on.

Argument Description
'menu' => 'primary', Use the menu slug provided by Underscores. Its name is "Primary Menu", and it's slug is "primary".
'theme_location' => 'primary', This menu belongs in the "Primary Menu" theme location.
'depth' => 2, How many levels of the hierarchy are to be included where 0 means all.
'container' => 'div', The HTML element that should wrap the list of menu items.
'container_class' => 'collapse navbar-collapse', HTML classes to apply to the container element.
'container_id' => 'primary-navigation', HTML id to apply to the container element.
'menu_class' => 'nav navbar-nav', HTML classes to apply to the menu element (<ul>)
'fallback_cb' => 'wp_bootstrap_navwalker::fallback', If the menu doesn't exist, the fallback function to use. This was suggested by the Bootstrap Nav Walker documentation.
'walker' => new wp_bootstrap_navwalker() Our new Bootstrap Nav Walker! This is where we have implemented the new file that we added to our theme earlier. This is the line of code that tells the menu to render using the Bootstrap HTML.

Whew. That's a lot. Good thing we don't need to memorize it.

If you need to add a menu to your WordPress theme in the future, refer to the codex documentation on this function: wp_nav_menu()

To see the exact changes you need to make, see this Git commit: Header.php work to create a Bootstrap Navbar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment