0

So I have created a wordpress template, and when i log in into wordpress there is a admin bar over main menu. This div wraps the other div's of the website. My question is: How can i set div margin-top: i.e. 50 pixels only when there is admin bar, ergo there is a user logged in?

EDIT:

So, this is my code of functions.php and it still doesnt work.

<?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:

I tried this too... It doesn't work.

<?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');
}

?>
4

3 回答 3

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
于 2013-11-12T23:27:53.180 回答
0

我通过添加解决了这个问题

<?php if ( is_user_logged_in() ) { ?>
<style  type="text/css" media="screen">
body{margin-top:28px !important;}
</style>
<?php } ?>

到functions.php

于 2013-11-13T21:06:52.903 回答
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
}
于 2019-09-06T16:20:10.690 回答