Setting the sidebar

Let's now get the sidebar set up so that we can add sidebar widgets:

  1. In the functions.php file underneath the add_action(), we will create a function called init_widgets() and that's going to take in an id. We will add register_sidebar() and that's going to take in an array. And then we have a bunch of options, so let's add 'name' => 'Sidebar' and 'id' => 'sidebar'.
      // Widget Locations      function init_widgets($id){          register_sidebar(array(              'name' => 'Sidebar',              'id'   => 'sidebar'          ));      }

We can also include other things here; for instance, we can add 'before_widget':

      'id' => 'sidebar',      'before_widget' => '<div class="panel panel-default">'

Now what this does is it allows us to insert code right before the widget renders. ...

Get Learn to Create WordPress Themes by Building 5 Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.