• Resolved kmessinger

    (@kmessinger)


    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)
  • are you using the ‘customizr’ theme?

    the ‘__before_header’ filter seems to specific to that theme, not generic to WordPress in general.

    Thread Starter kmessinger

    (@kmessinger)

    No, I am using a twentyfourteen child-theme.

    Thread Starter kmessinger

    (@kmessinger)

    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.

    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

    (@kmessinger)

    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.