如何以编程方式删除WordPress仪表板小部件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何以编程方式删除WordPress仪表板小部件相关的知识,希望对你有一定的参考价值。

  1. Simply paste the following into your functions.php file. The code will remove all dashboard widgets, so you should comment lines related to wigets you'd like to keep.
  2.  
  3. function remove_dashboard_widgets() {
  4. global $wp_meta_boxes;
  5.  
  6. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
  7. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
  8. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
  9. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
  10. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
  11. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
  12. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  13. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
  14.  
  15. }
  16.  
  17. if (!current_user_can('manage_options')) {
  18. add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
  19. }

以上是关于如何以编程方式删除WordPress仪表板小部件的主要内容,如果未能解决你的问题,请参考以下文章