WordPress后台并非千篇一律,你可以通过一些代码定制化一个你喜欢的后台,本文所述代码都应写在主题的functions.PHP中。
移除后台某些菜单
如果你不想客户因为点了错误的菜单选项而删除付费主题,或者搞乱后台的设置,那么把你不希望他们看到的菜单隐藏吧。将你想移除的菜单天道$restricted数组中即可
1 2 3 4 5 6 7 8 9 10 | 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 )]);} } } add_action( 'admin_menu' , 'remove_menus' ); |
更换登陆/注册页面的Logo
1 2 3 4 5 6 7 8 9 10 | function my_custom_login_logo() { echo ' <style type= "text/css" > .login h1 a { background-image:url( '.get_bloginfo(' template_directory ').' /images/custom-login-logo.gif) !important; } </style> '; } add_action( 'login_head' , 'my_custom_login_logo' ); |
更换Dashboard(仪表盘)的Logo
1 2 3 4 5 6 7 8 9 | add_action( 'admin_head' , 'my_custom_logo' ); function my_custom_logo() { echo ' <style type= "text/css" > #wp-admin-bar-wp-logo > .ab-item .ab-icon { background-image: url( '.get_bloginfo(' template_directory ').' /images/custom-logo.gif) !important; } </style>'; } |
删除“Please Upgrade Now”升级提示
1 2 3 4 5 6 7 8 9 10 11 | # 2.3 to 2.7: add_action( 'init' , create_function( '$a' , "remove_action( 'init', 'wp_version_check' );" ), 2 ); add_filter( 'pre_option_update_core' , create_function( '$a' , "return null;" ) ); # 2.8 to 3.0: remove_action( 'wp_version_check' , 'wp_version_check' ); remove_action( 'admin_init' , '_maybe_update_core' ); add_filter( 'pre_transient_update_core' , create_function( '$a' , "return null;" ) ); # 3.0: add_filter( 'pre_site_transient_update_core' , create_function( '$a' , "return null;" ) ); |
你也可以直接安装插件Disable WordPress Core Updates,隐藏升级通知在某些时候很有用,比如你要在低版本的wp上测试插件,或者你不想让你的客户被升级通知困扰。
删除Dashboard的Widget
如果你不想整天读WordPress官方的新闻,不想看见Dashboard到处是盒子,用下面的代码移除。虽然WordPress的屏幕选项也能实现差不多的效果,但从屏幕选项里去掉选择只不过是隐藏了这些widget,东西都在,只是你看不见罢了。用代码则可以禁止这些widget加载。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function remove_dashboard_widgets() { global $wp_meta_boxes ; unset( $wp_meta_boxes [ 'dashboard' ][ 'side' ][ 'core' ][ 'dashboard_quick_press' ]); 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' ][ 'normal' ][ 'core' ][ 'dashboard_plugins' ]); unset( $wp_meta_boxes [ 'dashboard' ][ 'normal' ][ 'core' ][ 'dashboard_recent_drafts' ]); unset( $wp_meta_boxes [ 'dashboard' ][ 'normal' ][ 'core' ][ 'dashboard_recent_comments' ]); unset( $wp_meta_boxes [ 'dashboard' ][ 'side' ][ 'core' ][ 'dashboard_primary' ]); unset( $wp_meta_boxes [ 'dashboard' ][ 'side' ][ 'core' ][ 'dashboard_secondary' ]); } add_action( 'wp_dashboard_setup' , 'remove_dashboard_widgets' ); |
创建自己的Dashboard Widget
1 2 3 4 5 6 7 8 9 10 11 | function example_dashboard_widget_function() { // Display whatever it is you want to show echo "Hello World, I'm a great Dashboard Widget" ; } // Create the function use in the action hook function example_add_dashboard_widgets() { wp_add_dashboard_widget( 'example_dashboard_widget' , 'Example Dashboard Widget' , 'example_dashboard_widget_function' ); } // Hoook into the 'wp_dashboard_setup' action to register our other functions add_action( 'wp_dashboard_setup' , 'example_add_dashboard_widgets' ); |
结束语
WordPress定制化很强,你可以有一个琳琅满目的后台,里面都是你需要和喜欢的东西;也许你想要一个简单加载速度快的后台,那么移除所有不需要的widget,删除所有没用的插件、主题。自由度大不是累赘,关键看如何使用。
https://blog.csdn.net/chaishen10000/article/details/71189303