Unregister before overriding a widget

When registering a new class to represent a widget of the same name, make sure to unregister the first widget before registering the new widget.

[code language=”php”]
add_action( ‘widgets_init’, function() {
// Doing it right
unregister_widget( ‘Plugin_Widget’ );
register_widget( ‘My_NamespacePlugin_Widget’ );
}, 11 );

If you don’t, WordPress will continue to use the update callback for the first widget class. Lovely.

Leave a Reply