wordpress自带了多个widget小工具,如近期文章、近期评论、分类目录等,非常实用,但是有些博主可能并不需要其中的部分小工具,而且也不想让它们显示在后台的小工具列表中,那wordpress怎么删除不需要的默认小工具widget?WordPress提供了小工具注销函数unregister_widget实现,通过该函数可以注销掉那些不想显示的小工具。
1 | unregister_widget( string|WP_Widget $widget ) |
$widget – (字符串| WP_Widget)WP_Widget子类的名称或WP_Widget子类的实例,即要注销的小工具的类名
删除近期评论、近期文章小工具代码
1 2 3 4 5 | function boke8_unregister_widget(){ unregister_widget('WP_Widget_Recent_Comments'); unregister_widget('WP_Widget_Recent_Posts'); } add_action('widgets_init','boke8_unregister_widget'); |
wp-includes/widgets.php
https://developer.wordpress.org/reference/functions/unregister_widget/