原網址:http://www.cnblogs.com/huangcong/p/3546636.html
WordPress作爲一博客管理系統,相對來說已經相當簡潔了,對用戶也十分友好,新手也極易上手。
儀表盤是我們登陸WordPress後看到的後臺界面,映入眼簾的是各種各樣的信息,如WordPress China博客消息,及其他關於WordPress的RSS信息,這些無用的東西空空的耗費着我們內存。通過定製WordPress的管理後臺,我們可以讓WordPress更加簡單實用,易於管理。簡化後臺界面,去除冗餘信息和代碼。
WordPress內置的hooks(包括filter和action)爲我們定製WordPress後臺提供了完美的解決方案。通過“勾入”而非修改WordPress的核心程序,可以在不影響安裝文件完整性的情況下安全地作改動。
下面介紹的代碼將全部在主題模板函數functions.php文件裏修改。
去除控制檯Widgets
//Remove dashboard widgets function remove_dashboard_widgets(){ global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } add_action('wp_dashboard_setup', 'remove_dashboard_widgets');
增加控制檯Widget
//Add dashboard widgets if ( ! function_exists( 'add_dashboard_widgets' ) ) : function welcome_dashboard_widget_function() { echo "<ul><li><a href='post-new.php'>發佈內容</a></li><li><a href='edit.php'>修改內容</a></li></ul>"; } function add_dashboard_widgets() { wp_add_dashboard_widget('welcome_dashboard_widget', '常規任務', 'welcome_dashboard_widget_function'); } add_action('wp_dashboard_setup', 'add_dashboard_widgets' ); endif;
去除小工具Widgets
//Disable Standard Widgets function remove_some_wp_widgets(){ unregister_widget('WP_Widget_Pages'); unregister_widget('WP_Widget_Calendar'); unregister_widget('WP_Widget_Archives'); unregister_widget('WP_Widget_Links'); unregister_widget('WP_Widget_Meta'); unregister_widget('WP_Widget_Search'); unregister_widget('WP_Widget_Text'); unregister_widget('WP_Widget_Categories'); unregister_widget('WP_Widget_Recent_Posts'); unregister_widget('WP_Widget_Recent_Comments'); unregister_widget('WP_Widget_RSS'); unregister_widget('WP_Widget_Tag_Cloud'); } add_action('widgets_init',remove_some_wp_widgets', 1);
刪除頂級菜單
//remove menus function remove_menus() { global $menu; $restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins')); end ($menu); while (prev($menu)){ $value = explode(' ',$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);} } } if ( is_admin() ) { add_action('admin_menu', 'remove_menus'); }
刪除子菜單
//remove submenus function remove_submenus() { global $submenu; unset($submenu['index.php'][10]); // Removes 'Updates'. unset($submenu['themes.php'][5]); // Removes 'Themes'. unset($submenu['options-general.php'][15]); // Removes 'Writing'. unset($submenu['options-general.php'][25]); // Removes 'Discussion'. unset($submenu['edit.php'][16]); // Removes 'Tags'. } add_action('admin_menu', 'remove_submenus');
根據角色設定菜單可見性
//remove role menus function remove_menus() { global $menu; // 這裏$restricted設置了評論和工具菜單 $restricted = array(__('Comments'), __('Tools')); end ($menu); while (prev($menu)){ $value = explode(' ',$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);} } } function remove_submenu() { remove_submenu_page( 'options-general.php', 'options-privacy.php' ); } global $current_user; get_currentuserinfo(); //如果當前用戶的等級小於3,那麼就刪除對應的菜單 if ($current_user->user_level < 3 && is_admin()) { add_action('admin_menu', 'remove_menus'); add_action('admin_init','remove_submenu'); }
0 級對應 訂閱者 1 級對應 投稿者 2 – 4 級對應 作者 5 – 7 級對應 編輯 8 – 10 級對應 管理員
修改後臺LOGO圖標
//custom admin logo function custom_logo() { echo '<style type="text/css"> #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/admin_logo.png) !important; } </style>'; } add_action('admin_head', 'custom_logo');
修改登錄頁面LOGO
//custom login logo function custom_login_logo() { echo '<style type="text/css"> h1 a { background-image:url('.get_bloginfo('template_directory').'/images/login_logo.png) !important; } </style>'; } add_action('login_head', 'custom_login_logo');
隱藏版本更新
//Hide the Upgrade Notice to Recent Versions add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
修改頁腳信息
//Customize the Footer function modify_footer_admin () { echo 'Created by <a href="http://wiinder.com">wiinder</a>.'; echo 'Powered by<a href="http://WordPress.org">WordPress</a>.'; } add_filter('admin_footer_text', 'modify_footer_admin');
去除編輯頁面媒體上傳按鈕
//remove all media buttons add_action('admin_init', 'remove_all_media_buttons'); function remove_all_media_buttons() { remove_all_actions('media_buttons'); }
完整刪除WP版本號
//完整的刪除WordPress的版本號 function wpbeginner_remove_version() { return ''; } add_filter('the_generator', 'wpbeginner_remove_version');
隱藏幫助按鈕和版本更新
//隱藏管理後臺幫助按鈕和版本更新提示 function hide_help() { echo'<style type="text/css">#contextual-help-link-wrap { display: none !important; } .update-nag{ display: none !important; } #footer-left, #footer-upgrade{ display: none !important; }#wp-admin-bar-wp-logo{display: none !important;}.default-header img{width:400px;}</style>'; } add_action('admin_head', 'hide_help');
去除header冗餘代碼
//去除header冗餘代碼 remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'start_post_rel_link', 10, 0); remove_action('wp_head', 'wp_generator');