Get a sidebar at the top of the page

This method works from your child themes functions.php file.

Change the hook to a different position:

//functions.php
function wpsites_register_widget() {

 register_sidebar( array(
'name' => 'After Header Widget',
'id' => 'after-header',
'before_widget' => '<div>',
'after_widget' => '</div>',
) );
}

    add_action( 'widgets_init', 'wpsites_register_widget' );

    add_filter( 'loop_start', 'after_header_widget', 25 );

    function after_header_widget() {


    if ( is_active_sidebar( 'after-header' ) ) { 
    dynamic_sidebar('after-header', array(
    'before' => '<div class="after-header">',
    'after' => '</div>',
) );


    }

}

Or you can call the sidebar directly in your template file.

<?php if ( is_active_sidebar( 'after-header' ) ) : ?>
<ul id="after-header">
<?php dynamic_sidebar( 'after-header' ); ?>
</ul>
<?php endif; ?>

Leave a Comment