WordPress 後台選單整理

打開 theme/functions.php 加入

/* 移除上方管理選單 */
function unix_remove_wp_admin_bar() {
global $wp_admin_bar;
// $wp_admin_bar->get_nodes(); 可取得所有選項
$wp_admin_bar->remove_menu( ‘wp-logo’ );
$wp_admin_bar->remove_menu( ‘comments’ );
$wp_admin_bar->remove_menu( ‘new-content’ );
$wp_admin_bar->remove_menu( ‘smof_options’ );
}
add_action( ‘wp_before_admin_bar_render’, ‘unix_remove_wp_admin_bar’, 999 );

/* 移除左側管理選單 */
function unix_menu_page_removing() {

//global $menu;
//print_r($menu); 印出現有選單

$user = wp_get_current_user(); // 取得登入者資訊
if($user->caps[‘administrator’] != 1) { // 判斷是否為最高管理帳號
remove_menu_page( ‘edit.php’ );
remove_menu_page( ‘edit-comments.php’ );
remove_menu_page( ‘edit.php?post_type=our-team’ );
remove_menu_page( ‘edit.php?post_type=testimonial’ );
remove_menu_page( ‘wpcf7’ );
remove_menu_page( ‘woocommerce’ );
remove_menu_page( ‘vc-welcome’ );
remove_menu_page( ‘tools.php’ );
}
}
add_action( ‘admin_menu’, ‘unix_menu_page_removing’, 999 );

發佈留言