duanchi3109 2014-02-20 20:49
浏览 51
已采纳

wordpress中的管理工具栏

I am developing my own wordpress theme for very first time. I want that when admin login to WordPress, at top admin tool bar must be show on main front end of website.

I tried following things

if (is_user_logged_in()) 
 {
    show_admin_bar(true);
 }#end if

in functions.php

What I believe that I missed some thing in header.php or index.php, but I am not sure.

  • 写回答

1条回答 默认 最新

  • doupingyun73833 2014-02-20 20:55
    关注

    The proper way to do this is with a filter in functions.php:

    function my_function_admin_bar(){
        return is_user_logged_in();
    }
    add_filter( 'show_admin_bar' , 'my_function_admin_bar');
    

    The admin bar is called as part of the wp_footer() function, so you need to make sure you call that function in your footer section of the template:

    <?php
       wp_footer();
    ?>
    

    A discussion of some specific issues that can cause this to break can be found here: http://wordpress.org/support/topic/admin-bar-not-displaying

    And finally, more details on how to use the show_admin_bar() in the functions.php file can be found here: http://codex.wordpress.org/Plugin_API/Filter_Reference/show_admin_bar

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角