Skip to content

Instantly share code, notes, and snippets.

@scottlee
Created November 1, 2012 15:30
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 scottlee/3994339 to your computer and use it in GitHub Desktop.
Save scottlee/3994339 to your computer and use it in GitHub Desktop.
Create a widgetized area for every top level page in WordPress.
/**
* 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