Created
June 7, 2014 18:31
-
-
Save chrisvanpatten/5cfd779d7a11e1d187f9 to your computer and use it in GitHub Desktop.
Automatically register sidebars for all pages on a WordPress site
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 | |
/** | |
* Per-page areas | |
*/ | |
$pages_args = array( | |
'post_type' => 'page', | |
'posts_per_page' => -1, | |
); | |
$pages = new WP_Query( $pages_args ); | |
if ( $pages->have_posts() ) { | |
while ( $pages->have_posts() ) { | |
$pages->the_post(); | |
global $post; | |
$args = array( | |
'name' => 'Page Sidebar: ' . get_the_title(), | |
'id' => $post->post_name . '-sidebar', | |
'before_widget' => '<aside id="%1$s" class="widget box %2$s">', | |
'after_widget' => '</aside>', | |
); | |
register_sidebar( $args ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment