What is the difference between wp_register_sidebar_widget and register_widget?

What’s the difference between them and when should we use each one ?

I’m using wp_register_sidebar_widget right now and it’s working fine but I’ve seen a lot of tutorials online on how to create a widget using register_widget and a class, most of my widgets doesn’t need options so should I stick to wp_register_sidebar_widget or should I use register_widget even if I don’t have a form ?

thanks in advance.

1
1

wp_register_sidebar_widget() is part of the old widgets API. Sidebar widgets used to be built procedurally … in a non-reusable fashion (i.e. you could only ever have one of each).

register_widget() was introduced with the new Widgets API and takes an object/class as an input rather than actual widget parameters. WordPress can instantiate as many copies of this widget as you need, allowing you to have several instances of the exact same widget.

You should be using individual widget classes and register_widget() even if your widget doesn’t have an input form.

Leave a Comment