您可以使用以下操作删除仪表板小部件/元框,wp_dashboard_setup
:
示例1
function remove_dashboard_widgets() {
global $wp_meta_boxes;
$wp_meta_boxes[\'dashboard\'][\'normal\'][\'core\'] = array();
$wp_meta_boxes[\'dashboard\'][\'side\'][\'core\'] = array();
}
add_action(\'wp_dashboard_setup\', \'remove_dashboard_widgets\', 100);
还有更具体的核心功能,
remove_meta_box()
其使用方式相同:
示例2
function remove_dashboard_widgets() {
remove_meta_box( \'dashboard_right_now\', \'dashboard\', \'normal\');
remove_meta_box( \'dashboard_activity\', \'dashboard\', \'normal\');
}
add_action(\'wp_dashboard_setup\', \'remove_dashboard_widgets\', 100);
上述操作将删除所有内容,如果您只想删除特定的小部件/元盒,那么请检查全局
$wp_meta_boxes
变量,尤其是
$wp_meta_boxes[\'dashboard\']
.
var_dump(array_keys($wp_meta_boxes[\'dashboard\'][\'normal\'][\'core\']));
var_dump(array_keys($wp_meta_boxes[\'dashboard\'][\'side\'][\'core\']));
在我的情况下,关键是:
/*
$wp_meta_boxes[\'dashboard\'][\'normal\'][\'core\'];
array (
0 => \'dashboard_right_now\',
1 => \'dashboard_activity\',
2 => \'woocommerce_dashboard_recent_reviews\',
3 => \'woocommerce_dashboard_status\',
)
$wp_meta_boxes[\'dashboard\'][\'side\'][\'core\'];
array (
0 => \'dashboard_quick_press\',
1 => \'dashboard_primary\',
)
*/
您可以相应地针对特定的小部件/元盒。
顺便提一下,如果您使用将空数组分配给相应键的方法,请注意如下所示example 1, 然后,应以高于100的优先级或您选择在其上删除它们的任何优先级添加在事件之后添加的任何后续元盒,否则您的小部件/元盒将不会显示。这就是为什么坚持WordPress的核心功能可能是一个更好的主意remove_meta_box()
如有疑问。