Snippets: 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
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( 'wpex_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;
} );

Snippet Type: PHP

Posted Under: Header

All PHP snippets should be added via a child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)