返回介绍

show_admin_bar()

发布于 2017-09-11 10:23:22 字数 2328 浏览 813 评论 0 收藏 0

show_admin_bar( bool $show )

Sets the display status of the admin bar.


description

This can be called immediately upon plugin load. It does not need to be called from a function hooked to the ‘init’ action.


参数

$show

(bool) (Required) Whether to allow the admin bar to show.


源代码

File: wp-includes/admin-bar.php

function show_admin_bar( $show ) {
	global $show_admin_bar;
	$show_admin_bar = (bool) $show;
}

更新日志

Versiondescription
3.1.0Introduced.

相关函数

Used By

  • wp-admin/includes/template.php: iframe_header()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::setup_theme()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

    Placing the below line of code in theme’s function.php file will prevent the Toolbar from rendering on the front end of your site.

    
    show_admin_bar( false );
    
  2. Selected display

    You can also determine for which users the admin bar is shown. For example the following lines will only display the admin bar for users with administrative privileges.

    
    if ( ! current_user_can( 'manage_options' ) ) {
        show_admin_bar( false );
    }
    

    The proper method for hiding the Toolbar on the front-end (cannot be disabled on the back-end).

    
    add_filter( 'show_admin_bar', '__return_false' );
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文