删除WP中的标准仪表板小部件,以便我可以替换为自定义

时间:2020-08-22 作者:Ted

下面的代码已经从WP仪表板中删除了一些但不是所有的小部件。我将它添加到我的主题内的函数文件中。我的问题有两个方面:

1)这是在使用;未定义常量“;remove\\u dashboard\\u meta、admin\\u init和manage\\u选项错误。

function remove_dashboard_meta() {

remove_meta_box( ‘dashboard_incoming_links’, ‘dashboard’, ‘normal’ );
remove_meta_box( ‘dashboard_plugins’, ‘dashboard’, ‘normal’ );
remove_meta_box( ‘dashboard_primary’, ‘dashboard’, ‘side’ );
remove_meta_box( ‘dashboard_secondary’, ‘dashboard’, ‘normal’ );
remove_meta_box( ‘dashboard_quick_press’, ‘dashboard’, ‘side’ );
remove_meta_box( ‘dashboard_recent_drafts’, ‘dashboard’, ‘side’ );
remove_meta_box( ‘dashboard_recent_comments’, ‘dashboard’, ‘normal’ );
remove_meta_box( ‘dashboard_right_now’, ‘dashboard’, ‘normal’ );
remove_meta_box( ‘dashboard_activity’, ‘dashboard’, ‘normal’);//since 3.8
}
add_action( ‘admin_init’, ‘remove_dashboard_meta’ );
第二个问题是Elementor概述和WPdeveloper提要仍然存在。什么代码将删除这些内容?这是WP 5.5

1 个回复
SO网友:Ted

上述示例的逗号类型错误,可能是复制和粘贴造成的。这是正确的类型

//Disable Default Dashboard Widgets
function remove_dashboard_meta() {
    remove_meta_box(\'dashboard_incoming_links\', \'dashboard\', \'normal\');
    remove_meta_box(\'dashboard_plugins\', \'dashboard\', \'normal\');
    remove_meta_box(\'dashboard_primary\', \'dashboard\', \'normal\');
    remove_meta_box(\'dashboard_secondary\', \'dashboard\', \'normal\'); 
    remove_meta_box(\'dashboard_quick_press\', \'dashboard\', \'side\');
    remove_meta_box(\'dashboard_recent_drafts\', \'dashboard\', \'side\');
    remove_meta_box(\'dashboard_recent_comments\', \'dashboard\', \'normal\');
    remove_meta_box(\'dashboard_right_now\', \'dashboard\', \'normal\');
    remove_meta_box(\'dashboard_activity\', \'dashboard\', \'normal\');
    remove_meta_box(\'rg_forms_dashboard\', \'dashboard\', \'normal\');
    remove_action(\'admin_notices\', \'update_nag\');
}
add_action(\'admin_init\', \'remove_dashboard_meta\');
第二个答案是,要删除Elementor及其概述,请使用以下代码:

remove_meta_box(\'e-dashboard-overview\', \'dashboard\', \'normal\');
Wordpress开发者提要小部件可以通过以下方式删除:

remove_meta_box(\'wpdev_feed_widget\', \'dashboard\', \'normal\');