A wordpress widget is a small component of an interface, that enables a user to perform various action. You can add, arrange, and remove widget from the sidebar of your blog. Widgets make it easy to customize the content of your sidebar of your blog.
**How to create wordpress widget**
to create a new widget in your wordpress CMS blog, you only need to extend the standard WP_Widget class and some of its functions.
Example:
class My_Widget extends WP_Widget {
/**
* Sets up the widgets name etc
*/
public function __construct() {
// widget actual processes
}
/**
* Outputs the content of the widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
// outputs the content of the widget
}
/**
* Outputs the options form on admin
*
* @param array $instance The widget options
*/
public function form( $instance ) {
// outputs the options form on admin
}
/**
* Processing widget options on save
*
* @param array $new_instance The new options
* @param array $old_instance The previous options
*/
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
}
}
// Register My_Widget widget
function register_my_widget() {
register_widget( 'My_Widget' );
}
add_action( 'widgets_init', 'register_my_widget' );
0 Comment(s)