Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am creating a custom theme, and elements behave as they should but when I place the <?php wp_head() ?> tag I get a top margin, at the top of my theme header.

When I remove the <?php wp_head(); ?> the margin goes away. I have been at this for a while any help would be great.

share|improve this question
1  
something that hooks into wp_head is outputting space before any html is output? –  Milo May 19 '11 at 4:15

7 Answers 7

The margin style block is output by the _admin_bar_bump_cb function which runs on the wp_head action. You can remove the action by calling:

remove_action('wp_head', '_admin_bar_bump_cb');

I placed it in my enqueue scripts function hook and it successfully removed the top margin output, but I'm sure you could place it anywhere in the functions.php and have it work correctly.

That way you don't need a silly override in your css =)

share|improve this answer

adding "margin-top: 0px !important" to the top of your CSS file actually will work, but ONLY if you re-arrange your header information to call the css file AFTER wp_head gets called.

the lowest CSS attribute will get applied, 100% of the time.

share|improve this answer
    
"The lowest CSS attribute will get applied, 100% of the time." - Not necessarily, depends on the specifity of other selectors that are present.. eg. #content div.somediv will always have priority over div.somediv regardless of where the latter is defined. –  t31os Apr 29 '13 at 9:02

I also encountered the same problem and I solved it by adding this:

html{ margin-top:0px !important;}

Put at the top of your theme's CSS file.

share|improve this answer
2  
this answer doesnt work because the 28px is added inline which takes precedence over anything in a css file –  user11913 Jan 10 '12 at 18:46

This happened with me as well, this space is for the admin bar at the top of your theme which gets displayed to a logged in user.

If you have logged in to your WordPress dashboard in the same browser in which you're using the custom theme, then there is the problem.

Simply log out from the WordPress admin account and open your custom theme again.

share|improve this answer

If you try to hide the Admin Bar by hooking into the show_admin_bar filter, but do this too late (init with the default priority is too late for example), you will get an extra 28px top margin but no admin bar there.

share|improve this answer

You should see what class is adding the margin with firebug or a similar tool.

share|improve this answer

Hard to saw without looking at it, but an educated guess:

More than likely it is the CSS for the admin bar, which only appears when you are logged in. the <?php wp_head() ?> will include the css for it, and <?php wp_footer(); ?> includes the html for the admin bar.

If you look, it should actually be a margin-top added to the html tag.

share|improve this answer
    
agreed, seen this problem a few times –  MartinJJ May 19 '11 at 7:48
1  
Yeah, I've helped out several people and seen this. I think the biggest issue is people not including the wp_footer() in template –  Ryan Gibbons May 19 '11 at 15:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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