🥳Remove an action from init in wordpress (ok)
https://stackoverflow.com/questions/47094179/remove-an-action-from-init-in-wordpress
PARENT THEME FUNCTION:
CHILD THEME FUNCTION: This is what I tried but it is not working.
How to Remove Default WordPress Widgets from Admin Screen
This is tested on WordPress 4.2 and 5.2. So it should work on any version in between. It may also work on lower versions as well but i have not tested.
The default widgets on WordPress admin panel are too many. I am talking about the widgets on appearance > widgets page. I had to remove these on a recent project. This guide shows you how to do that.
There are 2 scenarios here – remove all default widgets or remove only specific widgets.
Remove all default widgets
Let us remove all default widgets. Put the following code on your functions.php file.
Here wp_widgets_init is the action hook which registers all default wordpress widgets. By removing this hook with the code above we are preventing WordPress from registering all default widgets.
Hold on! We are not done yet!!
If you try the code above, the widgets will be removed, but you will find that now you can not add any custom widget! Why so? Because, the custom widgets are added through an action hook widgets_init which in turn depends on wp_widgets_init to fire. Removing wp_widgets_init removes widgets_init as well, hence you are unable to add custom widgets.
To overcome this problem, add another line below remove_action as follows
What this code does is – it removes the default widgets through first line and then immediately adds the action hook widgets_init back through the second line, allowing you to add any custom widget.
Note that the code above takes care of all future updates as well – which means if new default widgets are added to WordPress core, those will be removed as well without additional code.
Remove specific widget(s)
To remove a specific default widget, you will need to know the name of the widget class, and then unregister that widget using its class name .
For example, to remove the default Gallery widget add the following code to functions.php
Here 11 denotes the action priority. Which means the order with which this particular action will be executed. Why 11? Because default wordpress widgets are added with a priority of 10, hence in order to remove them you need to set an order greater than 10.
To remove multiple widgets you can use the following code. To make it easy i have listed all default widgets (as available under current WordPress verion 5.2). Again, this goes to functions.php!
Just un-comment the specific lines to remove respective widgets.
Did that work for you? Let me know in the comments below.
Last updated