Skip to content

Instantly share code, notes, and snippets.

@chered
Last active August 29, 2018 17:41
Show Gist options
  • Save chered/8d5a1304f55b08cfed327842cf0cb0bc to your computer and use it in GitHub Desktop.
Save chered/8d5a1304f55b08cfed327842cf0cb0bc to your computer and use it in GitHub Desktop.
//functions.php
add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar for Blog', 'theme-slug' ),
'id' => 'sidebar-blog',
'description' => __( 'Widgets in this area will be shown only on blog pages.', 'theme-slug' ),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
) );
}
//sidebar.php
<?php
$position = isset( $position ) ? $position : 'right';
$section = isset( $section ) ? $section : 'blog';
$size = isset( $size ) ? $size : '4';
$display = isset( $display ) ? $display : 'desktop';
?>
<div class="fl-sidebar fl-sidebar-<?php echo $position; ?> fl-sidebar-display-<?php echo $display; ?> col-md-<?php echo $size; ?>" itemscope="itemscope" itemtype="https://schema.org/WPSideBar">
<?php do_action( 'fl_sidebar_open' ); ?>
<?php //dynamic_sidebar( $section . '-sidebar' ); ?>
<?php
if( is_singular( 'blog' ) || is_taxonomy( 'blog_category' ) ){
dynamic_sidebar( 'sidebar-blog' );
}
else {
dynamic_sidebar( $section . '-sidebar' );
}
?>
<?php do_action( 'fl_sidebar_close' ); ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment