Skip to content

Snippet: Replace Header Aside Content with Widgets

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
add_filter( 'totaltheme/header/aside/content', function( $content ) {
	$header_aside_widgets = '';
		dynamic_sidebar( 'header_aside' );
	$header_aside_widgets = ob_get_clean();
	if ( $header_aside_widgets ) {
		$content = $header_aside_widgets;
	return $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)
Back To Top