Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/register sidebar widget

This function has been deprecated. That means it has been replaced by a new function or is no longer supported, and may be removed from future versions. All code that uses this function should be converted to use its replacement if one exists. See also wp-includes/deprecated.php. Use any of these functions instead.


Register widget for sidebar with backwards compatibility.

Provides backwards compatability to wp_register_sidebar_widget(). Registers callback as a widget output function with unique index name. This causes a draggable object containing name to appear in the admin interface.

A basic widget is simply a function that prints some HTML. To get a widget included in the widgets palette, you must register it via this function.

It is possible for theme authors to define replacement widgets within functions.php. Replace an existing widget by registering its name with a new callback. An empty callback will unregister a widget.

Because each widget has a unique name and a non-unique callback, the default markup before a widget looks like this:

<li id="{name}" class="{callback}">{callback output}</li>

When you register a widget you may pass a custom HTML class to replace callback. This is most useful for object-oriented widgets whose callbacks are passed as arrays.

Replace With



 <?php register_sidebar_widget$name$output_callback$classname ); ?> 


(string/int) (required) Widget ID.
Default: None
(callback) (required) Run when widget is called.
Default: None
(string) (optional) Classname widget.
Default: None


function my_widget {
    // print some HTML for the widget to display here.

register_sidebar_widget("my_widget", "my_widget");

Given a class my_widget whose method that prints the widget HTML is called display, you would use the following code:

class my_widget {
    function display() {
        // print some HTML for the widget to display here.

register_sidebar_widget('My Widget', array('my_widget', 'display')); // callback is mywidget::display

Change Log

Source File

register_sidebar_widget() is located in wp-includes/deprecated.php.


Widgets: is_active_widget(), the_widget(), register_widget(), unregister_widget(), wp_register_widget_control(), wp_unregister_widget_control(), wp_convert_widget_settings(), wp_get_widget_defaults(), wp_widget_description()

See also index of Function Reference and index of Template Tags.