Adding a search bar and single post page
So let's get started.
Dealing with the search box
Go to our header
file and go to the empty form down at the bottom of the file, and we will add some stuff to it. The first thing we'll do is adding a method and the method is going to be get
. We can actually change the class from left to right. We also need to add an action. For that, we will use the php
tags and add echo esc_url()
.
This is because we want the URL checked and escaped. We will use home_url
with a /
:
<form method="get" class="navbar-form navbar-right" role="search" action="<?php echo esc_url(home_url('/')); ?>">
Basically, we're just submitting to the home URL.
- Now as for the fields, we'll just want one field for
Search
, but let's add a label. So we will add<label for ="navbar-search"
and give it a class ofsr-only
. Next let's add<?php _e('Search')
, and this is just for localization of_e
. And then we need a second parameter oftextdomain
. Let's then close up those the...