title: Using sidebar.php within a Wordpress theme
body: <p>I have recently installed Woocommerce on a self-built theme and got an error message telling me that I needed to add a sidebar.php code to my theme. The error message was followed by a list of widgets in a messy, un-styled list. The widgets included a search bar, a list of pages in my site and an archives and categories list. I have now created sidebar.php by following a tutorial which seems to have worked – I have included the code I used below.</p>
  
  <p>What I'm finding unusual is that since adding the sidebar, these widgets seem to have disappeared and I now have to add them manually using the widgets tab under the appearance menu. I can't figure out why they might have disappeared? </p>
  
  <p>I always assumed that when adding a sidebar, I'd have to add the widgets via PHP code – otherwise wouldn't the sidebar clash with other templates? For example, I can add the Woocommerce widgets for my shop pages, but when I want to create blog posts I'll need different widgets, and the Woocommerce ones will still be in the sidebar and vice-versa. </p>
  
  <p>Maybe I've gone about doing this the wrong way.. perhaps somebody can point me in the right direction? I've been googling this and have watched some youtube tutorials but haven't found the answers I'm looking for.</p>
  
  <p>My code is as follows:</p>
  
  <p><strong>functions.php</strong></p>
  
  <pre><code>function enable_widgets() {
  
      register_sidebar(
          array(
              'name' =&gt; 'Main Sidebar',
              'id'   =&gt; 'sidebar',
              'description'   =&gt; 'Here you can add widgets to the main sidebar.',
              'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
              'after_widget'  =&gt; '&lt;/div&gt;',
              'before_title'  =&gt; '&lt;h5 id="widget-heading"&gt;',
              'after_title'   =&gt; '&lt;/h5&gt;'
      ));
  
   }
  
   add_action('widgets_init','enable_widgets');
  </code></pre>
  
  <p><strong>sidebar.php</strong></p>
  
  <pre><code>&lt;div class="sidebar"&gt;
      &lt;?php dynamic_sidebar('sidebar'); ?&gt;
  &lt;/div&gt;
  </code></pre>