Forums › Forums › Search & Filter Pro › How to remove the widget from the widget screen in admin?
Tagged: remove, unregister, widget
- This topic has 7 replies, 3 voices, and was last updated 8 years, 2 months ago by Anonymous.
-
Anonymous(Private) September 26, 2016 at 4:03 pm #60344
I’d like to remove the Search & Filter Pro widget from the Available Widgets in the widget screen in the backend, to keep things simple for the content manager. I’ll be adding Search & Filter Pro to the site through a template, so I don’t need to have the widget available.
I’ve removed many default WordPress widgets and a few from other plugins with my usual method: calling unregister_widget from the “widgets_init” action. This doesn’t seem to work for the Search & Filter widget. I’ve tried it using the widget base_id “search_filter_register_widget” at priorities 1, 10 and 100 but it doesn’t remove the widget. I can hide the widget with CSS, but that’s not ideal because it messes up the formatting of the other available widgets (they’re in two columns using floats on wider screens and it looks weird if I hide one with display:none).
Can anyone tell me how to remove the Search & Filter widget from the widget screen? Thanks in advance.
Anonymous(Private) September 27, 2016 at 9:53 am #60485I’ve tried that, but there’s no difference. Thanks for the suggestion though.
This is the function I’m using:
// Remove unwanted widgets function unregister_unwanted_widgets() { unregister_widget('WP_Widget_Pages'); unregister_widget('WP_Widget_Calendar'); unregister_widget('WP_Widget_Archives'); ... (more unregister calls here) ... unregister_widget('Search_Filter_Register_Widget'); } add_action('widgets_init', 'unregister_unwanted_widgets', 10);
Ross Moderator(Private) October 3, 2016 at 11:04 am #61525Hi there
Can you try (in functions.php):
add_action('widgets_init', 'init_widget'); function init_widget() { unregister_widget( 'Search_Filter_Register_Widget' ); }
I just realised the widget class is currently calledEdit – Scratch that, we will leave it calledSearch_Filter_Register_Widget
, I will be renaming this toSearch_Filter_Widget
in the next update, so you need both for future compatibility.Search_Filter_Register_Widget
for now, changing it loses all users’ currently defined widgets!Thanks
Anonymous(Private) October 3, 2016 at 11:44 am #61552Thanks guys, I found the problem with your help. I was doing everything right (using the same code Ross suggests above), but I was running it from my own plugin. Apparently, this messes with the order of execution or something (despite having tried different priorities for the add_action call), because it did nothing. Adding it to functions.php though, works.
Thank you for the support.
-
AuthorPosts