WordPress.org

Ready to get started?Download WordPress

Codex

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

Function Reference/wp register sidebar widget

Contents

Description

Register WordPress Widgets for use in your themes sidebars. You can also modify your theme and start Customizing Your Sidebar.

Usage

<?php 
wp_register_sidebar_widget
(
    
$id
    
$name
    
$output_callback
    
$options
    
$params,
    ... 
); 
?> 

Parameters

$id
(int/string) (required) Widget ID.
Default: None
$name
(string) (required) Widget display title.
Default: None
$output_callback
(callback) (required) Run when widget is called.
Default: None
$options
(array/string) (optional) Widget Options.
Default: None
$params,...
(mixed) (optional) Widget parameters to add to widget.
Default: None

Output Callback Function Parameters Format

function my_output_callback_function( $args, $params ){ ... }

$args
(array) (required) Various values merged into an array
Default: None
$params
(array) (required) The extra $params given to wp_register_sidebar_widget, as an array
Default: None

$args array contains:

The 'dynamic_sidebar_params' filter is applied to the parameters (as an array), before your output function is called back.

Example

The following code will create a widget called "Your Widget" which will become available in the WordPress Administrative Panels. The widget can then be dragged to an available sidebar for display.

Note that this widget can only be used once in exactly 1 of the sidebars. For recursive widgets (widgets you can add to multiple times and add to multiple sidebars) please see the Register Widget function.

<?php

function your_widget_display($args) {
   echo $args['before_widget'];
   echo $args['before_title'] . 'My Unique Widget' . $after_title;
   echo $args['after_widget'];
   // print some HTML for the widget to display here
   echo "Your Widget Test";
}

wp_register_sidebar_widget(
    'your_widget_1',        // your unique widget id
    'Your Widget',          // widget name
    'your_widget_display',  // callback function
    array(                  // options
        'description' => 'Description of what your widget does'
    )
);

?>

Change Log

Since: 2.2.0

Source File

wp_register_sidebar_widget() is located in wp-includes/widgets.php.

Related

Sidebars: is_active_sidebar(), is_dynamic_sidebar(), dynamic_sidebar(), register_sidebars(), register_sidebar(), unregister_sidebar(), wp_register_sidebar_widget(), wp_unregister_sidebar_widget(), wp_get_sidebars_widgets(), wp_set_sidebars_widgets()

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