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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.