admin管理员组文章数量:1026989
When I am logged in, there is a gray admin bar on top. My theme layout got distorted by the bar. How to solve the layout problem? Is there a function that can detect user is logged in or not, or use CSS can solve the problem ?
The theme demo is at: and below is the screenshot when the gray bar is there.
p.s. I use WordPress 3.2.1
& plugin Theme Test Drive
When I am logged in, there is a gray admin bar on top. My theme layout got distorted by the bar. How to solve the layout problem? Is there a function that can detect user is logged in or not, or use CSS can solve the problem ?
The theme demo is at: http://raptor.hk/dev/theme and below is the screenshot when the gray bar is there.
p.s. I use WordPress 3.2.1
& plugin Theme Test Drive
5 Answers
Reset to default 3The top bar of your theme is also positioned absolutely, so it doesn't know to come down. You can use is_admin_bar_showing()
to check to see if it's showing, and then I'd probably just inject some styles using wp_head
to move it down, since it's very little CSS.
All told, you'd get something in your theme's functions.php
like:
add_action( 'wp_head', 'prefix_move_theme_down' );
function prefix_move_theme_down() {
if ( is_admin_bar_showing() ) {
?>
<style type="text/css">
#header { top: 28px; }
#content { margin-top: 68px; }
</style>
<?php
}
}
The admin bar only shows up if you're logged in. If you don't like it at the top, you can always move it to the bottom. Add this to your theme's functions.php file:
<?php
function fb_move_admin_bar() {
echo '
<style type="text/css">
body {
padding-bottom: 28px;
}
body.admin-bar #wphead {
padding-top: 0;
}
body.admin-bar #footer {
padding-bottom: 28px;
}
#wpadminbar {
top: auto !important;
bottom: 0;
}
#wpadminbar .quicklinks .menupop ul {
bottom: 28px;
}
</style>';
}
add_action( 'admin_head', 'fb_move_admin_bar' );
add_action( 'wp_head', 'fb_move_admin_bar' );
?>
To hide the admin bar paste this function into function.php
function hide_admin_bar_from_front_end(){
if (is_blog_admin()) {
return true;
}
return false;
}
add_filter( 'show_admin_bar', 'hide_admin_bar_from_front_end' );
Add this into functions.php :
if ( is_admin_bar_showing() && !is_admin() )
_admin_bar_bump_cb();
This is default callback for the admin bar from wp-includes/admin-bar.php
:
function _admin_bar_bump_cb() { ?>
<style type="text/css" media="screen">
html { margin-top: 28px !important; }
* html body { margin-top: 28px !important; }
</style>
<?php
}
It seems as while the other answers do work, the clean and intended way to do this according to WordPress Core Code is this:
add_action( 'after_setup_theme', function(){
add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
} );
When I am logged in, there is a gray admin bar on top. My theme layout got distorted by the bar. How to solve the layout problem? Is there a function that can detect user is logged in or not, or use CSS can solve the problem ?
The theme demo is at: and below is the screenshot when the gray bar is there.
p.s. I use WordPress 3.2.1
& plugin Theme Test Drive
When I am logged in, there is a gray admin bar on top. My theme layout got distorted by the bar. How to solve the layout problem? Is there a function that can detect user is logged in or not, or use CSS can solve the problem ?
The theme demo is at: http://raptor.hk/dev/theme and below is the screenshot when the gray bar is there.
p.s. I use WordPress 3.2.1
& plugin Theme Test Drive
5 Answers
Reset to default 3The top bar of your theme is also positioned absolutely, so it doesn't know to come down. You can use is_admin_bar_showing()
to check to see if it's showing, and then I'd probably just inject some styles using wp_head
to move it down, since it's very little CSS.
All told, you'd get something in your theme's functions.php
like:
add_action( 'wp_head', 'prefix_move_theme_down' );
function prefix_move_theme_down() {
if ( is_admin_bar_showing() ) {
?>
<style type="text/css">
#header { top: 28px; }
#content { margin-top: 68px; }
</style>
<?php
}
}
The admin bar only shows up if you're logged in. If you don't like it at the top, you can always move it to the bottom. Add this to your theme's functions.php file:
<?php
function fb_move_admin_bar() {
echo '
<style type="text/css">
body {
padding-bottom: 28px;
}
body.admin-bar #wphead {
padding-top: 0;
}
body.admin-bar #footer {
padding-bottom: 28px;
}
#wpadminbar {
top: auto !important;
bottom: 0;
}
#wpadminbar .quicklinks .menupop ul {
bottom: 28px;
}
</style>';
}
add_action( 'admin_head', 'fb_move_admin_bar' );
add_action( 'wp_head', 'fb_move_admin_bar' );
?>
To hide the admin bar paste this function into function.php
function hide_admin_bar_from_front_end(){
if (is_blog_admin()) {
return true;
}
return false;
}
add_filter( 'show_admin_bar', 'hide_admin_bar_from_front_end' );
Add this into functions.php :
if ( is_admin_bar_showing() && !is_admin() )
_admin_bar_bump_cb();
This is default callback for the admin bar from wp-includes/admin-bar.php
:
function _admin_bar_bump_cb() { ?>
<style type="text/css" media="screen">
html { margin-top: 28px !important; }
* html body { margin-top: 28px !important; }
</style>
<?php
}
It seems as while the other answers do work, the clean and intended way to do this according to WordPress Core Code is this:
add_action( 'after_setup_theme', function(){
add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
} );
本文标签: cssHow to keep theme layout the same when admin gray bar is present
版权声明:本文标题:css - How to keep theme layout the same when admin gray bar is present? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745666106a2162187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论