所以我创建了一个wordpress模板,当我登录到wordpress时,主菜单上有一个管理栏。这个div包装了网站的其他div。 我的问题是: 如何设置div margin-top:即只有有管理栏时才有50个像素,ergo是否有用户登录?
编辑:
所以,这是我的functions.php代码,它仍然无法正常工作。
<?php
function new_excerpt_more( $more ) {
return '...<br /><br /><a href="'. get_permalink( get_the_ID() ) . '">Pročitaj još</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
?>
<?php
if(is_admin_bar_showing() && !is_admin()) {
function link_to_stylesheet() {
?>
<style type="text/css">#wrapper{margin-top:150px;}</style>
<?php
}
add_action('wp_head', 'link_to_stylesheet');
}
?>
EDIT2:
我也试过了......它不起作用。
<?php
if(is_admin_bar_showing() && !is_admin()) {
function link_to_stylesheet() {
?>
<style type="text/css">body{margin-top:150px;}</style>
<?php
}
add_action('wp_head', 'link_to_stylesheet');
}
?>
答案 0 :(得分:0)
要在前端管理栏中应用top:50px
,您可以尝试此操作(将其放入functions.php
)
if(is_admin_bar_showing() && !is_admin()) {
function link_to_stylesheet() {
?>
<style type="text/css">#wpadminbar {top:50px;}</style>
<?php
}
add_action('wp_head', 'link_to_stylesheet');
}
要完全删除管理栏,您可以尝试此操作(将其放入functions.php
)
add_filter('show_admin_bar', '__return_false');
仅针对非管理员用户从前端删除管理栏(将其放入functions.php
)
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
您可以通过从Users -> Your Profile
菜单中删除支票,从后端(仅限您自己)设置
Show Toolbar when viewing site check box
答案 1 :(得分:0)
我通过添加
解决了这个问题<?php if ( is_user_logged_in() ) { ?>
<style type="text/css" media="screen">
body{margin-top:28px !important;}
</style>
<?php } ?>
到functions.php
答案 2 :(得分:0)
只要有人登录并且前端有WPadminbar
将此添加到您的 functions.php :
function adminbar_theme_setup() {
add_theme_support( 'admin-bar', array( 'callback' => 'custom_admin_bar_css') );
}
add_action( 'after_setup_theme', 'adminbar_theme_setup' );
function custom_admin_bar_css() { ?>
<style>body{margin-top:28px !important;}</style>
<?php
}