How do register_sidebar() and get_sidebar() work together?

Written by  on August 12, 2016 

Disclaimer: I am brand spanking new to WP.

I am using the Starkers HTML5 framework theme ^(http://www.netaksharee.com/goto/http://nathanstaines.com/archive/starkers-html5-v3). In the functions.php I see this code:

function starkers_widgets_init() {

  // Area 1, located at the top of the sidebar.
  register_sidebar( array(
    'name' => __( 'Primary Widget Area', 'starkers' ),
    'id' => 'primary-widget-area',
    'description' => __( 'The primary widget area', 'starkers' ),
    'before_widget' => '<li>',
    'after_widget' => '</li>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
  ) );

  // Area 3, located in the footer. Empty by default.
  register_sidebar( array(
    'name' => __( 'First Footer Widget Area', 'starkers' ),
    'id' => 'first-footer-widget-area',
    'description' => __( 'The first footer widget area', 'starkers' ),
    'before_widget' => '<li>',
    'after_widget' => '</li>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
  ) );

  // ... more calls to register_sidebar() ...
}

And in footer.php I see this code:

<?php get_sidebar( 'footer' ); ?>

I don’t understand how get_sidebar() knows how to take that string argument and find the appropriate widgets that were defined by register_sidebar(). In the functions.php snippet I posted above. There isn’t any mention of “footer” except for the name, id and description properties. But it would seem odd to me that get_sidebar() would search for ‘footer’ inside those properties.

Does this make sense what I am asking? Is there some missing piece?

The reasons I am asking is because
– I would like to know more about the WP architecture
– I would like to be able to define a custom widget area and know how to render it on a specific page.

Thanks a ton.

Category : Wordpress

Tags :