WP-Mix

A fresh mix of code snippets and tutorials

Create WordPress widgets

WordPress makes it drop-dead simple to create your own custom widgets.

Just include the following code in your theme’s functions.php file:

class My_Widget extends WP_Widget {
	function My_Widget() {
		parent::WP_Widget(false, 'Our Test Widget');
	}
	function form($instance) {
		// outputs the options form on admin
	}
	function update($new_instance, $old_instance) {
		// processes widget options to be saved
		return $new_instance;
	}
	function widget($args, $instance) {
		// outputs the content of the widget
	}
}
register_widget('My_Widget');

With that in place, you’re all set to add whatever widget functionality you need.

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress