文章描述:
WordPress如何设置后台顶部工具栏
前台移除顶部工具栏
add_filter(\'show_admin_bar\', \'__return_false\');
移除Logo
移除顶部工具栏logo模块及下面的关于WordPress、WordPress.org、文档、支持、反馈
function remove_wp_logo() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(\'wp-logo\');
}
add_action( \'wp_before_admin_bar_render\', \'remove_wp_logo\' );
移除升级按钮
function disable_bar_updates() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(\'updates\');
}
add_action( \'wp_before_admin_bar_render\', \'disable_bar_updates\' );
移除评论
function remove_comment_bubble() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(\'comments\');
}
add_action( \'wp_before_admin_bar_render\', \'remove_comment_bubble\' );
移除新建模块
移除顶部工具栏新建模块下面的文章、媒体、页面、用户
function disable_new_content() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(\'new-content\');
}
add_action( \'wp_before_admin_bar_render\', \'disable_new_content\' );
添加一个带连接的按钮
function custom_adminbar_menu( $meta = TRUE ) {
global $wp_admin_bar;
if ( !is_user_logged_in() ) { return; }
if ( !is_super_admin() || !is_admin_bar_showing() ) { return; }
$wp_admin_bar->add_menu( array(
\'id\' => \'custom_menu\',
\'title\' => __( \'网站首页\' ), /* 这里是按钮的名称 */
\'href\' => get_option(\'home\'), /* 注意改里面的链接 */
\'meta\' => array( \'target\' => \'_blank\' ) )
);
}
add_action( \'admin_bar_menu\', \'custom_adminbar_menu\', 100 );
/* add_action后面的15是按钮的位置,具体修改看下
10 = 在WP Logo之前
15 = 在WP Logo之后
25 = 在网站名称之后
100 = 最后 */
添加一个菜单和带下来的按钮
function custom_adminbar_menu( $meta = TRUE ) {
global $wp_admin_bar;
if ( !is_user_logged_in() ) { return; }
if ( !is_super_admin() || !is_admin_bar_showing() ) { return; }
$wp_admin_bar->add_menu( array(
\'id\' => \'custom_menu\',
\'title\' => __( \'工具\' ) ) /* 更改按钮名称 */
);
$wp_admin_bar->add_menu( array(
\'parent\' => \'custom_menu\',
\'id\' => \'custom_links\',
\'title\' => __( \'百度一下\'), /*更改链接 */
\'href\' => \'https://www.baidu.com/\', /* 更改链接地址 */
\'meta\' => array( \'target\' => \'_blank\' ) )
);
}
add_action( \'admin_bar_menu\', \'custom_adminbar_menu\', 15 );
© 版权声明
THE END
请登录后查看评论内容