Skip to content

Instantly share code, notes, and snippets.

@saramarie
Created April 7, 2013 15:55
Show Gist options
  • Select an option

  • Save saramarie/5331041 to your computer and use it in GitHub Desktop.

Select an option

Save saramarie/5331041 to your computer and use it in GitHub Desktop.
WordPress: Easy way to create new widget areas
/*================================================
= Widget Area Registration =
================================================*/
$widget_list = array (
// Create a new sidebar by adding its name here
'Primary Sidebar',
'Left Footer',
'Left Center Footer',
'Right Center Footer',
'Right Footer'
);
if (function_exists('register_sidebar')) {
$count = 0;
foreach ($widget_list as $widget) {
$widget_id = str_replace(' ', '_', strtolower($widget));
$widget_set[$count] = array (
'name' => $widget,
'id' => $widget_id,
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
);
$count++;
}
for ($i = 0; $i < $count; $i++) {
register_sidebar($widget_set[$i]);
}
}
/*----- End of Widget Area Registration ------*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment