How to add widget in header

edit functions.php and add

function wpb_widgets_init() {
register_sidebar( array(
'name' => 'Header Widget',
'id' => 'header-widget',
'before_widget' => '<div class="hw-widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="hw-title">',
'after_title' => '</h2>',
) );

}
add_action( 'widgets_init', 'wpb_widgets_init' );


now edit header.php and add:

 <?php if ( is_active_sidebar( 'header-widget' ) ) : ?>     <div id="header-widget-area" class="hw-widget widget-area" role="complementary"> <?php dynamic_sidebar( 'header-widget' ); ?>     </div> <?php endif; ?> 

Author