ปัญหา
html {
margin-top: 32px !important;
}ปรากฏใน css ไม่ได้อยู่ในไฟล์ css ใด จะแก้ก็ไม่ได้
ที่แท้มันคือ Admin Bar CSS นั่นเอง
ซึ่งจะเกิดขึ้นกับ browser ที่ยังอยู่ในสถานะ login เข้า Admin ขอ wordpress อยู่
ดังนั้นถ้า logout ออกไป ก็จะไม่เห็นแล้ว
วิธีลบ
Remove WordPress Admin Bar CSS
A version or two back, WordPress decided to add a toolbar for logged in users on the display side that’s about the site’s theme. I get why they did it but it’s an annoyance to me — I don’t care to see it. To accomplish this task, WordPress injects the following into every page
<style type="text/css" media="print">#wpadminbar { display:none; }</style>
<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>Bleh. You can remove this CSS and the admin bar using the following code which should be placed with your functions.php file:
add_action('get_header', 'remove_admin_login_header');
function remove_admin_login_header() {
remove_action('wp_head', '_admin_bar_bump_cb');
}มันมาจาก css นี้
<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>is added for Admin bar by wp-core at the top of the site.
The trick below will remove those CSS out from yout HTML output Just add this code to your functions.php
add_action('get_header', 'my_filter_head');
function my_filter_head() {
remove_action('wp_head', '_admin_bar_bump_cb');
}https://wordpress.stackexchange.com/questions/200352/wp-head-gives-me-some-weird-css
หรือ แก้โดย
function remove_admin_login_header() {
remove_action('wp_head', '_admin_bar_bump_cb');
}
add_action('get_header', 'remove_admin_login_header');https://stackoverflow.com/questions/25491619/how-to-delete-margin-top-32px-important-from-twenty-twelve