Last active
November 25, 2015 08:06
-
-
Save talentedaamer/9aeb1fc2f738bcb68f32 to your computer and use it in GitHub Desktop.
Generate Unlimited Sidebars/Widget Areas using a single array();
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* theme widgets and widget areas | |
*/ | |
add_action ( 'widgets_init', 'oopthemes_register_sidebar' ); | |
function oopthemes_register_sidebar( $sidebars = array() ) { | |
foreach ( $sidebars as $name ) { | |
/** | |
* sidebar name, make the words uppercase | |
* @var string : each name of the sidebar in the array | |
*/ | |
$name = ucwords( $name ); | |
/** | |
* id of the sidebar, spaces are converted to "-" | |
* @var string : each name of the sidebar is converted to id with "-" | |
*/ | |
$id = strtolower( str_replace( ' ', '-', $name ) ); | |
/** | |
* args to register a sidebar | |
* @var array : list of arguments to register a sidebar | |
* name : name of the sidebar | |
* id : id of the sidebar | |
* before_widget : html before widget area | |
* after_widget : html after widget area | |
* before_title : html before widget title | |
* after_title : html after widget title | |
* | |
*/ | |
$args = array( | |
'name' => $name, | |
'id' => $id, | |
'before_widget' => '<div id="%1" class="widget %2">', | |
'after_widget' => '</div>', | |
'before_title' => '<h3 class="widget-title">', | |
'after_title' => '</h3>' | |
); | |
register_sidebar( $args ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment