Skip to content

Instantly share code, notes, and snippets.

@matiskay
Created December 14, 2011 19:22
Show Gist options
  • Save matiskay/1478047 to your computer and use it in GitHub Desktop.
Save matiskay/1478047 to your computer and use it in GitHub Desktop.
Wordpress Widget Skeleton
<?php
class Widget_Name extends WP_Widget {
function Widget_Name() {
$widget_opts = array(
'classname' => 'your-awesome-class',
'description' => 'Your awesome Description',
);
$this->WP_Widget('your_awesome_cool_name', 'Awesome Title', $widget_opts);
}
// widget outputs the widget content.
function widget($args, $instance) {
}
// displays the form which shows on the Widgets management panel.
function form($instance) {
$output = '';
$instance = (array) $instance;
$instance = wp_parse_args($instance, array('number' => 2 ));
$title = esc_attr($instance['title']);
// More Code
echo $output;
}
// updates the widget options when saved.
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}
}
// Load and Register the widget
add_action('widgets_init', 'awesome_plugin_name_load_widgets');
function awesome_plugin_name_load_widgets() {
register_widget('Widget_Name');
}
@ChangJoo-Park
Copy link

Thanks matiskay

@punit5658
Copy link

Hi, $this->WP_Widget() is deprecated so use parent::__construct() instead of $this->WP_Widget().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment