移除wordpress仪表盘中无用的模块

  • A+
所属分类:WordPress技巧

wordpress 默认的后台登陆界面是仪表盘,界面上有很多我们看到的新闻订阅,插件信息等,看着不怎么舒服,而且会拖慢后台打开速度。本次教程是通过在主题中添加代码的方式来实现移除不需要的模块。下面这段代码放到主题的 functions.php,可移除相应的模块。

function example_remove_dashboard_widgets() {
    // 全局化 metaboxes 数组,该数组包含了 wp-admin 中的所有小工具
    global $wp_meta_boxes;

    // 删除 "快速发布" 小工具
    if (isset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'])) {unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
    }

    // 删除 "引入链接" 小工具
    if (isset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links'])) {unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
    }

    // 删除 "插件" 小工具
    if (isset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins'])) {unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
    }

    // 删除 "近期评论" 小工具
    if (isset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments'])) {unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    }

    // 删除 "近期草稿" 小工具
    if (isset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts'])) {unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
    }

    // 删除 "WordPress 开发日志" 小工具
    if (isset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'])) {unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    }

    // 删除 "其他 WordPress 新闻" 小工具
    if (isset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary'])) {unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
    }

    // 删除 "概况" 小工具
    if (isset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now'])) {unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    }
}

add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets');

其实可以直接 unset+(执行的代码)就行了,但是为了安全以确保只有在相应的小工具存在时才进行删除操作,避免产生错误。如果想要直接移除小工具也可以直接写入,无需判断。

function example_remove_dashboard_widgets() {
// Globalize the metaboxes array, this holds all the widgets for wp-admin  
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_plugins']);
// 以下这一行代码将删除 "近期评论" 模块  
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
// 以下这一行代码将删除 "近期草稿" 模块  
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
// 以下这一行代码将删除 "WordPress 开发日志" 模块  
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
// 以下这一行代码将删除 "其它 WordPress 新闻" 模块  
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
// 以下这一行代码将删除 "概况" 模块  
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
}
add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets');

🆗然后就完成啦。

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: