Title: Problem adding a widget above header
Last modified: August 22, 2016

---

# Problem adding a widget above header

 *  Resolved [kmessinger](https://wordpress.org/support/users/kmessinger/)
 * (@kmessinger)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-adding-a-widget-above-header/)
 * I added this to my child theme functions.
 *     ```
       <?php
       // Add a widget.
       if (function_exists('register_sidebar')) {
       	register_sidebar(array(
       	'name' => 'Extra Widget Before Header',
       	'id' => 'extra-widget',
       	'description' => 'Extra Widget Before Header',
       	'before_widget' => '<div id="%1$s" class="widget %2$s">',
       	'after_widget' => '</div>',
       	'before_title' => '<h2>',
       	'after_title' => '</h2>'
       	));
       }
       // Place the widget before the header
       add_filter ('__before_header', 'add_my_widget');
       function add_my_widget() {
       	if (function_exists('dynamic_sidebar')) {
       	dynamic_sidebar('Extra Widget Before Header');
       }
       }
       ```
   
 * It added the widget above header to my widget menu with no problem but whatever
   I put there does not publish to the blog.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-adding-a-widget-above-header/#post-5721027)
 * are you using the [‘customizr’ theme](https://wordpress.org/themes/customizr)?
 * the ‘__before_header’ filter seems to specific to that theme, not generic to 
   WordPress in general.
 *  Thread Starter [kmessinger](https://wordpress.org/support/users/kmessinger/)
 * (@kmessinger)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-adding-a-widget-above-header/#post-5721098)
 * No, I am using a twentyfourteen child-theme.
 *  Thread Starter [kmessinger](https://wordpress.org/support/users/kmessinger/)
 * (@kmessinger)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-adding-a-widget-above-header/#post-5721108)
 * This works for me.
 *     ```
       <?php
       /** Register Before Post Widget Area.*/
       function wpsites_before_header_widget() {
   
       	 register_sidebar( array(
       		'name' => 'Before Header Widget',
       		'id' => 'before-header',
       		'before_widget' => '<div>',
       		'after_widget' => '</div>',
       	) );
       }
       add_action( 'widgets_init', 'wpsites_before_header_widget' );
   
       /** Hook In Widget Before Header Site Wide */
       function before_header_widget() {
   
               if ( is_active_sidebar( 'before-header' ) ) {
                   dynamic_sidebar('before-header', array(
       	    'before' => '<div class="before-header widget-area">',
                   'after' => '</div>',
       	) );
   
           }
   
       }
   
       add_action( 'wp_head', 'before_header_widget', 25 );
       ```
   
 * Thanks for your help. That was for customizr.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-adding-a-widget-above-header/#post-5721218)
 * caveat:
 * your tweak might work, however, as ‘wp_head’ is usually inserted and executed
   before the body tag, this will likely lead to invalid html code.
 *  Thread Starter [kmessinger](https://wordpress.org/support/users/kmessinger/)
 * (@kmessinger)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-adding-a-widget-above-header/#post-5721236)
 * You are correct. Validation shows, </div></head>, a Stray end tag head.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Problem adding a widget above header’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [kmessinger](https://wordpress.org/support/users/kmessinger/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/problem-adding-a-widget-above-header/#post-5721236)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
