WordPress.org

Codex

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

Plugin API/Action Reference/wp register sidebar widget

Description

This hook is called once for each widget that is registered. A widget is generally registered using the register_widget() function, defined in wp-includes/widget.php.

Parameters

$widget
(WP_Widget object) (optional) The instance of the WP_widget object that is being registered.
Default: None

Usage

<?php
  add_action( 'wp_register_sidebar_widget', 'my_function' );

  function my_function( $widget ){
     // do something with $widget
  }
?>

Sample WP_Widget object

    [name] => Pages
    [id] => pages-1
    [callback] => Array
        (
            [0] => WP_Widget_Pages Object
                (
                    [id_base] => pages
                    [name] => Pages
                    [widget_options] => Array
                        (
                            [classname] => widget_pages
                            [description] => Your site’s WordPress Pages
                        )

                    [control_options] => Array
                        (
                            [id_base] => pages
                        )

                    [number] => 1
                    [id] => pages-1
                    [updated] => 
                    [option_name] => widget_pages
                )

            [1] => display_callback
        )

    [params] => Array
        (
            [0] => Array
                (
                    [number] => -1
                )

        )

    [classname] => widget_pages
    [description] => Your site’s WordPress Pages

Examples

<?php
  add_action( 'wp_register_sidebar_widget', 'my_function' );

  function my_function( $widget ){
     // In this case we only want to do something with the default 'Pages' widget
     if ( 'Pages' === $widget['name'] ){
       // Found the widget we wanted... do something really cool here.
     }
  }
?>

Change Log

  • Since: 2.2.0

Source

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

Related

This page is marked as incomplete. You can help Codex by expanding it.