WordPress自定义仪表盘(Dashboard)

    2015-12-03 13:16     0 条评论

隐藏Widget

正如方法一结尾所说,从屏幕选项中去除只是表面上隐藏了,还是会占用网速、内存。如果想彻底移除,就用程序来做。方法如下:

打开当前主题的functions.php,在文件末尾加上一段代码,这段代码用移除钩子的方式去掉widget

下面是代码

function remove_dashboard_widgets() {
    global $wp_meta_boxes;

    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);    //快速发布
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);    //WordPress China 博客
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);  //其它WordPress新闻
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);  //近期草稿

    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_comments']);//近期评论
}
add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );

移除左侧菜单

下面是代码:

/**
 *  移除Dashboard中无用的左侧菜单
 * */

//is_blog_admin

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(strpos($value[0], '<') === FALSE) {
            if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){
                unset($menu[key($menu)]);
            }
        }
        else {
            $value2 = explode('<', $value[0]);
            if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){
                unset($menu[key($menu)]);
            }
        }
    }
}

if ( is_admin() ) {
    // 删除左侧菜单
    add_action('admin_menu', 'remove_menus');
}

本文地址:https://www.yhawaii.net/wordpress-dashboard.html
版权声明:本文为原创文章,版权归  所有,欢迎分享本文,转载请保留出处!

 发表评论


表情