• Hi!

    Since two of the standard widgets supplied by the plugin are making trouble with the theme I’ve developed, I want to unregister them so they don’t appear in the panel.

    However a

    unregister_sidebar_widget('Calendar');
    unregister_sidebar_widget('Search');

    , which should be correct according to the plugin API, doesn’t seem to work, the widgets still appear in the panel. Am I missing something?

    Cheers, Jeriko

Viewing 5 replies - 1 through 5 (of 5 total)
  • The trick is unregistering them after the widgets plugin registers them. Since it registers them using the ‘init’ action hook at priority 5, the following will unregister them:

    function unregister_them() {
    unregister_sidebar_widget('Calendar');
    unregister_sidebar_widget('Search');
    }
    add_action('init','unregister_them',10);

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    While that will indeed work, it’s not the best way. Relying on the priority is haphazard at best. Useful for a quick fix and such, but not really something you want to depend on.

    A better way is to notice that the widgets plugin has its own action hook for this sort of thing, called “widgets_init”. It happens just after the Widgets plugin registers all its own widgets.

    function unregister_problem_widgets() {
    unregister_sidebar_widget('Calendar');
    unregister_sidebar_widget('Search');
    }
    add_action('widgets_init','unregister_problem_widgets');

    Good call, Otto42.

    Thread Starter Jeriko

    (@jeriko)

    Works like a charm, thank you so much

    Thank you very much, same here. Works like charm.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Widgets: Unregistering standard widgets’ is closed to new replies.