Skip to content

Instantly share code, notes, and snippets.

Created February 6, 2018 15:49
What would you like to do?
This is how to create custom widget
*Creating custom widgets
*Check out the tuts:
class mwp_wid extends WP_Widget{
function mwp_wid(){
parent::WP_Widget(false, $name = "MWP Test Widgets");
function form($instance){
$name = esc_attr($instance['name']);
<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Your Name:'); ?></label>
<input id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" type="text" value="<?php echo $name; ?>" />
function update($new_instance,$old_instance){
$instance = $old_instance;
$instance['name'] = strip_tags($new_instance['name']);
return $instance;
function widget($args, $instance) {
extract( $args );
// these are the widget options
$name = $instance['name'];
echo $before_widget;
// Check if options are set
if( $name ) {
echo '<p class="wp_widget_plugin_textarea" style="font-size:25px;">'.$name.'</p>';
echo $after_widget;
add_action('widgets_init', create_function('', 'return register_widget("mwp_wid");'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment