How to Disable Standard Widgets in WordPress

Home » Snippets » How to Disable Standard Widgets in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you tired of the standard widgets cluttering up your WordPress dashboard? Do you wish you could disable them and only display the widgets that are relevant to your website? If so, you’re in luck. In this article, we will show you how to disable the standard widgets in WordPress, allowing you to declutter your dashboard and focus on the widgets that matter most to you.

					function wpturbo_disable_standard_widgets() {
    unregister_widget( 'WP_Widget_Categories' );
    unregister_widget( 'WP_Widget_Recent_Posts' );
    unregister_widget( 'WP_Widget_Recent_Comments' );
    unregister_widget( 'WP_Widget_RSS' );
    unregister_widget( 'WP_Widget_Meta' );
    unregister_widget( 'WP_Widget_Search' );
}
add_action( 'widgets_init', 'wpturbo_disable_standard_widgets' );
				

The code snippet provided above demonstrates how to disable or unregister standard widgets in WordPress. This can be useful if you want to remove certain default widgets from the Widgets area in the WordPress admin.

The wpturbo_disable_standard_widgets() function is created to unregister specific widgets. In this example, we are choosing to unregister the following widgets: WP_Widget_Categories, WP_Widget_Recent_Posts, WP_Widget_Recent_Comments, WP_Widget_RSS, WP_Widget_Meta, and WP_Widget_Search.

Each unregister_widget() function call passes in the widget class name as a parameter. By registering the desired widgets to be unregistered, we are essentially removing them from the Widgets area.

unregister_widget( 'WP_Widget_Categories' );
unregister_widget( 'WP_Widget_Recent_Posts' );
unregister_widget( 'WP_Widget_Recent_Comments' );
unregister_widget( 'WP_Widget_RSS' );
unregister_widget( 'WP_Widget_Meta' );
unregister_widget( 'WP_Widget_Search' );

You can customize this list and add or remove any other widgets that you want to disable. Simply add or remove unregister_widget() lines as needed, providing the appropriate widget class names.

Lastly, we need to hook the wpturbo_disable_standard_widgets() function into the widgets_init action using the add_action() function. This action is triggered when WordPress initializes the widgets. By doing this, the function will be called and the specified widgets will be unregistered, effectively disabling them.

add_action( 'widgets_init', 'wpturbo_disable_standard_widgets' );

Once you have added this code to your WordPress theme’s functions.php file or a custom plugin, the standard widgets you have chosen to unregister will no longer be visible in the Widgets area of the WordPress admin.

Register an account to save your snippets or go Pro to get more features.