04/10/2018, 19:55

Cách gỡ bỏ link trong WordPress Admin Bar

Kể từ phiên bản WordPress 3.3 ra đời, thì nó có thêm vài icon và link khác nhau, nhưng nếu các bạn không muốn một số user có quyền truy cập những link này thì các bạn hoàn toàn có thể loại bỏ chúng. Để loại bỏ những link này thì các bạn chỉ việc vào file functions.php và chèn đoạn code sau. ...

Kể từ phiên bản WordPress 3.3 ra đời, thì nó có thêm vài icon và link khác nhau, nhưng nếu các bạn không muốn một số user có quyền truy cập những link này thì các bạn hoàn toàn có thể loại bỏ chúng.

Cách gỡ bỏ link trong WordPress Admin Bar

Để loại bỏ những link này thì các bạn chỉ việc vào file functions.php và chèn đoạn code sau.

function remove_admin_bar_links() {
    global $wp_admin_bar;
    $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('w3tc');             // If you use w3 total cache remove the performance link
    $wp_admin_bar->remove_menu('my-account');       // Remove the user details tab
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );

Tuy nhiên đoạn code bên trên sẽ loại bỏ link cho tất cả các user, nếu các bạn muốn admin thấy được các link này thì chỉnh sửa lại đoạn code như sau.

function remove_admin_bar_links() {
    global $wp_admin_bar, $current_user;
    
    if ($current_user->ID != 1) {
        $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('w3tc');             // If you use w3 total cache remove the performance link
        $wp_admin_bar->remove_menu('my-account');       // Remove the user details tab
    }
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );

Chúc các bạn thành công !

Tags: code Snipppets wordpress code

Chuyên Mục: WordPress

Bài viết được đăng bởi webmaster

0