Snippet: Replace Header Aside Content with Widgets
This snippet will specifically for developers looking to do this task with code. Instead you could register a new custom sidebar via the Custom Widget Areas Panel and then insert the WPBakery [[vc_widget_sidebar sidebar_id="YOUR_SIDEBAR_ID"]] shortcode into the Customizer's header aside content box instead.
This snippet will register a new "Header Aside" widget area under Appearance > Widgets or Customize > Widgets which you can use to add widgets to the header aside area.
// Register new sidebar area - you could also do this via Appearance > Widget Areas.
add_action( 'widgets_init', function() {
register_sidebar( array(
'name' => esc_html__( 'Header Aside', 'total' ),
'id' => 'header_aside',
'before_widget' => '<div id="%1$s" class="widget %2$s clr">',
'after_widget' => '</div>',
'before_title' => '<span class="widget-title">',
'after_title' => '</span>',
) );
} );
// Replace header aside content with widgets if the widget area isn't empty.
function myprefix_modify_header_aside_content( $content ) {
$header_aside_widgets = '';
ob_start();
dynamic_sidebar( 'header_aside' );
$header_aside_widgets = ob_get_clean();
if ( $header_aside_widgets ) {
$content = $header_aside_widgets;
}
return $content;
}
add_filter( 'totaltheme/header/flex/aside/content', 'myprefix_modify_header_aside_content' );
add_filter( 'totaltheme/header/aside/content', 'myprefix_modify_header_aside_content' );
All PHP snippets should be added via child theme's functions.php file or via a plugin.
We recommend Code Snippets (100% Free) or WPCode (sponsored)
We recommend Code Snippets (100% Free) or WPCode (sponsored)