TianDev

Xóa menu ngang trên thanh Admin bar WordPress

Posted: September 30, 2019 by anhkevin

Admin bar là một khu vực ở trên cùng của màn hình được hiển thị cho người dùng đã đăng nhập vào WordPress. Đây là một thanh ngang dài có chứa các phím tắt tới các phần khác nhau của màn hình WordPress admin.

Để xóa menu trên thanh admin bar sử dụng action: wp_before_admin_bar_render

<?php

function remove_menu_in_admin_bar() { 
    global $wp_admin_bar; 
    
    // Xóa menu: 
    $wp_admin_bar->remove_menu('NAME_MENU'); //Một số menu mặc định 
    $wp_admin_bar->remove_menu('wp-logo'); // Remove the WordPress logo 
    $wp_admin_bar->remove_menu('about'); // Remove the about WordPress link 
    $wp_admin_bar->remove_menu('wporg'); // Remove the WordPress.org link 
    $wp_admin_bar->remove_menu('documentation'); // Remove the WordPress documentation link 
    $wp_admin_bar->remove_menu('support-forums'); // Remove the support forums link 
    $wp_admin_bar->remove_menu('feedback'); // Remove the feedback link 
    $wp_admin_bar->remove_menu('site-name'); // Remove the site name menu 
    $wp_admin_bar->remove_menu('view-site'); // Remove the view site link 
    $wp_admin_bar->remove_menu('updates'); // Remove the updates link 
    $wp_admin_bar->remove_menu('comments'); // Remove the comments link 
    $wp_admin_bar->remove_menu('new-content'); // Remove the content link 
    $wp_admin_bar->remove_menu('my-account'); // Remove the user details tab 
} 
add_action( 'wp_before_admin_bar_render', 'remove_menu_in_admin_bar' );

Lưu ý: Cách nhận biết NAME_MENU

B1. Nhấn chuột phải vào thanh admin bar và bấm inspect (hoặc bấm Ctrl + Shift + I)

B2. Dò đến đoạn html của thanh admin bar và chú ý có đoạn <li id="wp-admin-bar-xxxxx" ….. .xxxxx chính là NAME_MENU. 

B3. Sử dụng hàm trên với NAME_MENU vừa tìm ở B2 => Thế là xong