相关类:WP_Admin_Bar
Class: Core class used to implement the Toolbar API.核心类:用于执行工具栏API
global $wp_admin_bar;
WP_Admin_Bar::add_menu
add_action( ‘admin_bar_menu’, ‘modify_admin_bar’ );
function modify_admin_bar( $wp_admin_bar ){
// do something with $wp_admin_bar;
}
相关插件
- Hide Admin Bar
- Auto Hide Admin Bar
- Hide Admin Bar from Non-Admins
- Admin Bar & Dashboard Access Control
- Hide Admin Bar From Front End
- Always Show Admin Bar
- WP Admin Bar Control
举例
例1:
add_action( ‘admin_bar_menu’, ‘modify_admin_bar’ );
function modify_admin_bar( $wp_admin_bar ){
// do something with $wp_admin_bar;
}
例2:Disable Admin Bar for All Users Except for Administrators关闭,所有用户 除了管理员。
Paste this code in your theme’s functions.php file or your site-specific plugin.
add_action(‘after_setup_theme’, ‘remove_admin_bar’);
function remove_admin_bar() {
if (!current_user_can(‘administrator’) && !is_admin()) {
show_admin_bar(false);
}
}
Disable Admin Bar for All Users
If you want to disable it for all users, then simply put use this code in your theme’s functions.php file or your site-specific plugin.
/* Disable WordPress Admin Bar for all users but admins. */
show_admin_bar(false);
相关函数
show_admin_bar:https://developer.wordpress.org/reference/functions/show_admin_bar/
举例:
show_admin_bar( false );
说明: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.
参考阅读
10+关于WORDPRESS顶部工具栏(ADMINBAR)的小技巧
wordpress除去顶部烦人的工具条(admin bar)
How to Disable WordPress Admin Bar for All Users Except Administrators
发表评论
要发表评论,您必须先登录。