所以我创建了一个 wordpress 模板,当我登录到 wordpress 时,主菜单上有一个管理栏。这个 div 包裹了网站的其他 div。 我的问题是: 我如何设置 div margin-top:即仅当有管理栏时才 50 像素,因此有用户登录?
编辑:
所以,这是我的 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');
}
?>
编辑2:
这个我也试过了……没用。
<?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');
}
?>
最佳答案
要在前端的管理栏中应用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
关于php - WordPress 管理栏和模板 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19941657/