- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/register sidebar widget
Description
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.
Usage
%%% <?php register_sidebar_widget( $name, $output_callback, $classname ); ?> %%%
Parameters
- $name
- (string/int) (必須) Widget ID.
- 初期値: なし
- $output_callback
- (callback) (必須) Run when widget is called.
- 初期値: なし
- $classname
- (string) (optional) Classname widget.
- 初期値: なし
Example
<?php 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:
<?php 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
Since: 2.2.0
Source File
register_sidebar_widget() is located in wp-includes/widgets.php
.
最新英語版: WordPress Codex » Function Reference/register_sidebar_widget (最新版との差分)
Related
ウィジェット API: is_active_widget(), the_widget(), register_widget(), unregister_widget() / en, wp_register_widget_control() / en, wp_unregister_widget_control() / en, wp_convert_widget_settings() / en, wp_get_widget_defaults() / en, wp_widget_description() / en