Created
November 1, 2012 15:30
-
-
Save scottlee/3994339 to your computer and use it in GitHub Desktop.
Create a widgetized area for every top level page in WordPress.
This file contains hidden or 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
/** | |
* Create widgetized sidebars for each page | |
*/ | |
function xxx_custom_page_sidebars() { | |
$pages = get_pages( array( | |
'parent' => 0 | |
) | |
); | |
foreach ( $pages as $page ) { | |
register_sidebar( array( | |
'name' => $page->post_title, | |
'id' => 'sidebar-' . $page->post_name, | |
'description' => 'This is the widgetized area for the \'' . $page->post_title . '\' page.', | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => '</aside>', | |
'before_title' => '<h3 class="widget-title">', | |
'after_title' => '</h3>', | |
)); | |
} | |
} | |
add_action( 'widgets_init', 'xxx_custom_page_sidebars' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment