PHPSOFT SOLUTIONS LOGO
  • Home
  • About Us
  • Contact Us
  • Contact Us
  • Blog
  • Online Courses
  • Contact US

How to Create Custom Widgets With custome functionality.

Step 1

Extend WP_widget class

class MyNewWidget extends WP_Widget () /* WP_Widget class located in wp-includes/widgets.php */

Step 2
function MyNewWidget() {
// Instantiate the parent object
//parent::__construct( false, ‘My New Widget Title’ );

$widget_ops = array(
‘classname’ => ‘postsfromcat’,
‘description’ => ‘Allows you to display a list of
thumbnail posts’);

$control_ops = array(
‘width’ => 250,
‘height’ => 250,
‘id_base’ => ‘widget-19_mynewwidget-6’);

$this->WP_Widget(‘widget-19_mynewwidget-6’, ‘thumbnail’, $widget_ops, $control_ops );
}

}

/*$widget_ops -> you cen set custom class name and description according to your widget.

$control_ops-> set widht, height and id of ur widget(widget id is created automaticaly,when your widget is created)

Step 3

function widget( $args, $instance ) {
// Widget output

extract($args); /*you need to extract argument from widget class.

$title = $instance[‘title’];  //get textbox value like this.

//write functionality,whatever you want.

}

Step  4

function update( $new_instance, $old_instance ) {
// Save widget options

//save value of textbox like this.

$instance[‘title’] = $new_instance[‘title’];
return $instance;

}

Step 5

function form( $instance ) {

// Output admin widget options form?>

//write HTML,whatever you want to show in widget.

}
}

Step 6

//register your custom widget

function myplugin_register_widgets() {
register_widget( ‘MyNewWidget’ );

}

//hook your custom widget with widget in it.

add_action( ‘widgets_init’, ‘myplugin_register_widgets’ );

 

 

 

Posted on December 2013
Category: Wordpress

Categories

  • Blog
  • phonegap
  • PHP Frameworks
  • php-jquery
  • system
  • Wordpress
  • Yii

Post navigation

Previous post

symlinks with Win7

Next post

how to add meta option in post and pages.


PHPSOFT SOLUTIONS LOGO

Our mission is to satisfy our customers to the best.Money is the source nowdays, the trust of how we can use your money in the best way is build by us.The core value of php soft solutions is to provide the best service to our customers in a great manner.

Contact

PLOT NO. C157, The Groove, Industrial focal point, Phase7,MOHALI, SAS Nagar, Punjab, 160055

8146501814

contact@phpsoftsolutions.in

Pages Links
  • WordPress
  • Yii
  • PHP Frameworks
  • php-jquery
  • system
  • phonegap

© 2025 PHPSOFT SOLUTIONS