How To Create a WordPress Widget

Published on : April 6, 2015

Author:

Category: Wordpress


WordPress is one of the popular and powerful content management system .

It is immensely popular among the developers because of it’s flexibility, lots of plugins, security, lots of themes and widgets. Today we will create a custom widget for WordPress.

WordPress API  contains the technical details.


class wp_plugin extends WP_Widget {
   // Constructor for initialize element
   function wp_plugin() {
      // Code
   }

   // Widget form

   function form($instance) {
      //Widgets Form design
   }

   // widget update

   function update($new_instance, $old_instance) {
      //Update Code going here
   }

   // widget display

   function widget($args, $instance) {
      //Display goes here
   }
}

// register widget

add_action('widgets_init', create_function('', 'return register_widget("wp_plugin");'));

In  Constructor  You can define your widget name


public function __construct() {
   parent::WP_Widget(false,’Widget title’,’description=What type of widget is it’);
}