WordPress 後台屏幕右上角有兩個小工具:顯示選項 (Screen Options) 和幫助 (Help),作為定製化 Dashboard 的一部分,某些時候需要將這兩個小東西隱藏,隱藏的方法如下。

隱藏顯示選項

在主題的 functions.php 中寫如下代碼

function remove_screen_options(){ return false;}
add_filter('screen_options_show_screen', 'remove_screen_options');

對 Editor(編輯) 一下級別的用户隱藏顯示選項

function remove_screen_options(){
if( !current_user_can('publish_pages') )
return false;
return true;
}
add_filter('screen_options_show_screen', 'remove_screen_options');

隱藏幫助選項卡

在主題的 functions.php 中添加

add_filter( 'contextual_help', 'wpse50723_remove_help', 999, 3 );
function wpse50723_remove_help($old_help, $screen_id, $screen){
$screen->remove_help_tabs();
return $old_help;
}

兼容性

WP 3.4+

兩種方法都能正常工作

WP 3.3+ <WP 3.4

兩種方法都起作用,但移除 screen options 的同時也會是所有的 Dashboard Widgets 顯示出問題,需要添加一些額外的樣式修復

WP 3.0+ <WP 3.3

remove_help_tabs() 未定義,所以要使用另一種方式

add_filter('contextual_help', '__return_false');

這只是移除了幫助信息,幫助那個 menu 鏈接還是無法移除,只能用 CSS 的 display:none 來搞定了

移除 screen options 同樣會導致 Dashboard Widgets 顯示錯誤,需要添加額外樣式修復。只能説 WordPress 這幾個版本 Dashboard 佈局雖然變化不大,但 div 的 class 卻變了不少。