Skip to content

Instantly share code, notes, and snippets.

@SeanJA
Created October 6, 2010 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanJA/613303 to your computer and use it in GitHub Desktop.
Save SeanJA/613303 to your computer and use it in GitHub Desktop.
<?php
//to have multiple sidebars in wordpress:
function mytheme_widgets_init() {
register_sidebar(array(
'name' => __( 'sidebar1', 'mytheme' ),
'id' => 'sidebar1-area',
'description' => __( 'The first sidebar area', 'mytheme' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => __( 'sidebar2', 'mytheme' ),
'id' => 'sidebar2-area',
'description' => __( 'The second sidebar area', 'mytheme' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => __( 'sidebar3', 'mytheme' ),
'id' => 'sidebar3-area',
'description' => __( 'The third sidebar area', 'mytheme' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
}
/** Register sidebars by running mytheme_widgets_init() on the widgets_init hook. */
add_action( 'widgets_init', 'mytheme_widgets_init' );
/**
* Use a specific sidebar (if it is active)
* @param string $sidebar the sidebar you want to use
* @param string $sidebarId the id to add to the sidebar
*/
function use_sidebar($sidebar, $sidebarId){
if ( is_active_sidebar( $sidebar ) ): ?>
<div id="<?php echo $sidebarId ?>" class="widget-area" role="complementary">
<ul class="xoxo">
<?php dynamic_sidebar( $sidebar ); ?>
</ul>
</div>
<?php endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment