Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active December 18, 2015 02:28
Show Gist options
  • Save robneu/5710749 to your computer and use it in GitHub Desktop.
Save robneu/5710749 to your computer and use it in GitHub Desktop.
Set a different sidebar for all blog posts and archives on the Genesis Framework
<?php
/**
* Swap default sidebar for the blog sidebar
* on blog posts and archives.
*
* @author FAT Media
* @link http://youneedfat.com
*/
add_action( 'genesis_after_header', 'mytheme_change_blog_sidebar' );
function mytheme_change_blog_sidebar() {
if ( is_single() || is_page_template( 'page_blog.php' ) || ( is_archive() && ! is_post_type_archive() ) ) {
//* Make sure blog sidebar has widgets
if ( is_active_sidebar( 'blog-sidebar' ) ) {
remove_action('genesis_after_content','genesis_get_sidebar' );
add_action( 'genesis_after_content', 'mytheme_get_blog_sidebar' );
}
//* Output the blog slidebar
function mytheme_get_blog_sidebar() {
$site_layout = genesis_site_layout();
//* Make sure the layout isn't full width
if ( $site_layout == 'full-width-content' )
return;
echo '<div id="sidebar" class="sidebar widget-area">';
dynamic_sidebar( 'blog-sidebar' );
echo '</div>';
}
}
}
/** Register a blog sidebar */
genesis_register_sidebar( array(
'id' => 'blog-sidebar',
'name' => __( 'Blog Sidebar', 'mytheme' ),
'description' => __( 'This is the default sidebar for the blog section.', 'mytheme' ),
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment