I want to get a sidebar ( get_sidebar( 'mySidebar' ) ) at the top of the page, so I can't call it after get_header() in the content template. How could I do it?


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

Change the hook to a different position:

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' ); ?>
<?php endif; ?>
  • I've tried, but the sidebar is called after the navigation bar. I want to call it before.
    – Manolo
    Jan 13 '14 at 10:51
  • Use the template code before the nav Jan 13 '14 at 10:55
  • Well, I thought that overriding header.php file wasn't a recommended method.
    – Manolo
    Jan 13 '14 at 12:41
  • It is fine to create a header.php in your child theme. It might not be ideal and you should review your header.php to see if there are any hooks you might be able to add after_header_start() to. Impossible to say without seeing your header.php file. Jan 13 '14 at 12:57

Yes you can, call it after get_header().
Make sure sidebar-{name}.php i.e sidebar-mySidebar.php file is present.
Otherwise let me know the error.

  • The problem is that I want to call it before all the elements in the page, so calling it after header will put the sidebar content below the "nav-bar".
    – Manolo
    Jan 13 '14 at 9:59
  • then you can copy header.php file and call sidebar before navigation menu.
    – shahpranaf
    Jan 13 '14 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.