admin管理员组文章数量:1335135
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.
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.
- 1 something that hooks into wp_head is outputting space before any html is output? – Milo Commented May 19, 2011 at 4:15
8 Answers
Reset to default 12Hard 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.
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.
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 =)
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.
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.
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.
You should see what class is adding the margin with firebug or a similar tool.
Try this,
html { margin-top:0px; padding-top:0px; }
本文标签: wp headWhy is wphead() creating a top margin at the top of my theme header
版权声明:本文标题:wp head - Why is wp_head() creating a top margin at the top of my theme header? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742217798a2434886.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论