如何定制 WordPress 后台仪表盘指定模块的显示

来源: 老季博客
日期: 2020-3-23
作者: 腾讯云/服务器VPS推荐评测/Vultr
阅读数: 45

WordPress 的后台仪表盘应该是每个站长们每天都要使用的吧!今天明月就分享一个定制显示 WordPress 后台仪表盘指定模块的代码,以方便大家定制自己需求的 WordPress 后台仪表盘来。

只需要根据自己的需要选择下面的代码加入到主题 function.php 里即可,这里可以参考【如何方便的在更新主题时保留 functions.php 里的自定义』一文里的方法来防止主题更新后 function.php 被覆盖造成的失效问题。

// 以下这一行代码将删除 "welcome" 模块
remove_action('welcome_panel', 'wp_welcome_panel');
//删除 WordPress 后台仪表盘
function disable_dashboard_widgets() {
    global $wp_meta_boxes;
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
}
add_action('wp_dashboard_setup', 'disable_dashboard_widgets', 999);

function custom_dashboard_help() {
    echo '这里填使用说明的内容,可填写HTML代码';
}
function example_add_dashboard_widgets() {
    wp_add_dashboard_widget('custom_help_widget', '这里替换成面板标题', 'custom_dashboard_help');
}
add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );

具体大家可以参考上述代码里的中文注释来选择了,其实很简单的都是,只需要复制粘贴即可了。

链接到文章: https://jiloc.com/46644.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注