1

I wrote a theme and the top admin / tool bar is not showing. I still see an empty margin. Any ideas?

Here the top margin I never set anywhere in my files.

I actually want to show the toolbar completely.

enter image description here

  • 3
    Maybe wp_footer() is missing? – birgire Apr 16 '14 at 1:18
  • how the heck should I know I HAVE to place this, to achieve this? are there other hidden treasures out there like this? – Toskan Apr 16 '14 at 4:03
3

It looks like your theme is missing the wp_footer() function, but is containing the wp_header() function.

I can replicate this behavior on the default themes, by removing wp_footer().

The HTML for the admin bar comes from this part in the Core code:

add_action( 'wp_footer', 'wp_admin_bar_render', 1000 );

It's usually informative to check out the default themes:

The last three lines in the footer.php file in the TwentyTen, TwentyEleven, TwentyTwelve, TwentyThirteen, TwentyFourteen themes are:

<?php wp_footer(); ?>
</body>
</html>

Keep in mind that writing a good theme is not an easy task.

You only have to read the theme review process on wordpress.org to see the hard work involved.

The following comes through the wp_head() function, for logged in users:

  • the admin-bar stylesheet, is coming

    <link rel='stylesheet' 
          id='admin-bar-css' 
          href='http://example.com/wp-includes/css/admin-bar.min.css?ver=3.8.3'   
          type='text/css' 
          media='all' />
    
  • the extra white space comes from this part within the <head> tags:

    <style type="text/css" media="screen">
        html { margin-top: 32px !important; }
        * html body { margin-top: 32px !important; }
        @media screen and ( max-width: 782px ) {
            html { margin-top: 46px !important; }
            * html body { margin-top: 46px !important; }
        }
    </style>
    

    when the users have the toolbar option selected on their profile page:

    toolbar option

  • the part to disable the admin bar when printing:

    <style type="text/css" media="print">#wpadminbar { display:none; }</style>
    

To wrap it up:

If you're logged in, with the toolbar option selected, the theme pages will have an extra space (32px) at the top. This space is filled up with the admin bar HTML blocks from the wp_footer(), so make sure you include this function in your theme's footer.

Hope this helps.

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.