WordPress是高度可定制的,只要我们在后台添加样式和页面,就可以基本实现所需的效果。 本文将与你分享一些…
WordPress是高度可定制的,只要我们在后台添加样式和页面,就可以基本实现所需的效果。 本文将与你分享一些自定义功能的方法,包括在仪表盘上添加和删除小工具,删除背景菜单,小部件等。
去除控制台 Widgets
1 2 3 4 5 6 7 8 9 10 11
|
//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
1 2 3 4 5 6 7 8 9 10 11 12
|
//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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
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);
|
删除顶级菜单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
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’); }
|
删除子菜单
1 2 3 4 5 6 7 8 9
|
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’);
|
根据角色设定菜单可见性
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
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,那么就删除对应的菜单
1 2 3 4
|
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 图标
1 2 3 4 5 6 7 8 9
|
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
1 2 3 4 5 6 7 8 9
|
function custom_login_logo() {
echo ‘<style type=”text/css”>
h2 a {
background-image:url(‘.
get_bloginfo(‘template_directory’).
‘/images/login_logo.png) !important; }
</style>’; }
add_action(‘login_head’, ‘custom_login_logo’);
|
隐藏版本更新
1
|
add_filter( ‘pre_site_transient_update_core’, create_function( ‘$a’, “return null;” ) );
|
修改页脚信息
1 2 3 4 5
|
function modify_footer_admin () {
echo ‘Created by <a external-link=”true” href=”http://www.febdays.com”>二月繁华</a>.’;
echo ‘Powered by<a external-link=”true” href=”http://WordPress.org”>WordPress</a>.’; }
add_filter(‘admin_footer_text’, ‘modify_footer_admin’);
|
去除编辑页面媒体上传按钮
1 2 3 4
|
add_action(‘admin_init’, ‘remove_all_media_buttons’); function remove_all_media_buttons(){
remove_all_actions(‘media_buttons’); }
|
完整删除 WP 版本号
1 2 3 4 5
|
//完整的删除 WordPress 的版本号 function wpbeginner_remove_version() {
return ”; }
add_filter(‘the_generator’, ‘wpbeginner_remove_version’);
|
隐藏帮助按钮和版本更新
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
//隐藏管理后台帮助按钮和版本更新提示 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 冗余代码
1 2 3 4 5 6 7
|
//去除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’);
|
还没有任何评论,赶紧来占个楼吧!