Categories
Wordpress

Creating a custom widget

Here is the basic code to use to create a widget.

class myWidget extends WP_Widget {
function myWidget() {
// widget actual processes
parent::WP_Widget(false, $name = ‘myWidget’);
}

function form($instance) {
// outputs the options form on admin
}

function update($new_instance, $old_instance) {
// processes widget options to be saved
}

function widget($args, $instance) {
// outputs the content of the widget
?>
<li> …
</li>
<?
}

}
register_widget(‘myWidget’);