Title: Modifying widget functions within a theme
Last modified: August 19, 2016

---

# Modifying widget functions within a theme

 *  [sdickert](https://wordpress.org/support/users/sdickert/)
 * (@sdickert)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/)
 * Wanting to revise the elements within a widget, but do not want to continually
   update the theme elements.
 * How do I separate the widget update (e.g. WP_Calendar_Widget in default-widgets.
   php) so I can change the elements of it – without having to modify the theme 
   or the core codebase?
 * Thanks in advance.

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736628)
 * Copy the class and functions, give the class another name, then use the newly
   modified version..
 * Eg.
 *     ```
       // Example - trimmed
   
       class WP_Widget_Calendar_Custom extends WP_Widget {
   
       	function WP_Widget_Calendar() {
       ```
   
 * You can then change what you want…
 *  Thread Starter [sdickert](https://wordpress.org/support/users/sdickert/)
 * (@sdickert)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736669)
 * Mark – thanks for the feedback. My other question is where do I place the code
   so when the theme updates, it will not get rewritten?
 * Thanks.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736673)
 * Place the code into a plugin? A standalone php file will work fine..
 * Only need contain the new class with your adjustments, just ensure you give the
   php file a plugin header… like so..
 *     ```
       <?php
       /*
       Plugin Name: Some-unique-plugin-name
       */
       ```
   
 *  Thread Starter [sdickert](https://wordpress.org/support/users/sdickert/)
 * (@sdickert)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736679)
 * Mark – thanks again. I got the plugin – enabled it – and am trying to figure 
   out how to override the original widgets versus keeping the ones in the default.
 * I went to the widgets interface on the Admin side and now I see a slew of inactive
   widgets and I do not see my new ones. Have I forgotten something?
 *  Thread Starter [sdickert](https://wordpress.org/support/users/sdickert/)
 * (@sdickert)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736703)
 * I have looked into adding the widgets – like this:
 * // register widgets
    add_action(‘widgets_init’, create_function(”, ‘return register_widget(“
   WP_PoliGastro_Widget_Calendar”);’));
 * and I get this error from the plugin (which is calling a problem in the codebase):
 * Warning: Missing argument 2 for WP_Widget::__construct(), called in /home/content/
   s/d/i/sdickert/html/phs80s/wp-includes/widgets.php on line 324 and defined in/
   home/content/s/d/i/sdickert/html/phs80s/wp-includes/widgets.php on line 93
 *  Thread Starter [sdickert](https://wordpress.org/support/users/sdickert/)
 * (@sdickert)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736705)
 * Okay – last effort – I have tried coding this – and can not find a simple way
   to register the modified Calendar class. See the code below:
 *     ```
       <?php
       /**
        * @package 2010 Mods
        * @version 1.0
        */
       /*
       Plugin Name: 2010 Modifications
       Plugin URI: http://sanforddickert.com/#
       Description: This makes modifications to the standard twentyten theme to enable Political Gastronomica
       Author: Sanford Dickert
       Version: 1.0
       Author URI: http://sanforddickert.com/
       */
   
       /**
        * PG Calendar widget class
        *
        * @since 2.8.0
        */
       class WP_PoliGastro_Widget_Calendar extends WP_Widget {
   
       	function WP_PoliGastro_Widget_Calendar() {
       		$widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A PoliGastro calendar of your site’s posts') );
       		$this->WP_Widget('calendar', __('Calendar'), $widget_ops);
       	}
   
       	function widget( $args, $instance ) {
       		extract($args);
       		$title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
       		echo $before_widget;
       		if ( $title )
       			echo $before_title . $title . $after_title;
       		echo '<div id="calendar_wrap2">';
       		get_calendar();
       		echo '</div>';
       		echo $after_widget;
       	}
   
       	function update( $new_instance, $old_instance ) {
       		$instance = $old_instance;
       		$instance['title'] = strip_tags($new_instance['title']);
   
       		return $instance;
       	}
   
       	function form( $instance ) {
       		$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
       		$title = strip_tags($instance['title']);
       ?>
       		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
       		<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
       <?php
       	}
       }
   
       /**
        * Register all of the default WordPress widgets on startup.
        *
        * Calls 'widgets_init' action after all of the WordPress widgets have been
        * registered.
        *
        * @since 2.2.0
        */
   
       // register widgets
       //register_widget('WP_PoliGastro_Widget_Calendar');
   
       ?>
       ```
   
 *  Thread Starter [sdickert](https://wordpress.org/support/users/sdickert/)
 * (@sdickert)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736739)
 * Got it.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736758)
 * Sorry i didn’t reply sooner, not been at my PC… did you manage to get the code
   working ok?
 * Should be a simple case of copying code and renaming a few areas, but let me 
   know if you still have problems… 😉
 *  Thread Starter [sdickert](https://wordpress.org/support/users/sdickert/)
 * (@sdickert)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736786)
 * I found the changes – needed to modify some of the parameters and then add_action
   efforts. I grabbed another plug-in and checked how they did it. No one has rewritten
   any of the default widgets (e.g. Calendar, Recent Posts) in a plug in – I was
   wondering if there was a way instead of creating two new widgets.
 * Any thoughts?
 *  Thread Starter [sdickert](https://wordpress.org/support/users/sdickert/)
 * (@sdickert)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736789)
 * BTW – for future readers – here is the code snippets I made:
 *     ```
       <?php
       /**
        * @package 2010 Mods
        * @version 1.0
        */
       /*
       Plugin Name: 2010 Modifications
       Plugin URI: http://sanforddickert.com/#
       Description: This makes modifications to the standard twentyten theme to enable Political Gastronomica
       Author: Sanford Dickert
       Version: 1.0
       Author URI: http://sanforddickert.com/
       */
   
       /**
        * PG Calendar widget class
        *
        * @since 2.8.0
        */
       class WP_PoliGastro_Widget_Calendar extends WP_Widget {
   
       	function WP_PoliGastro_Widget_Calendar() {
       		$widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A PoliGastro calendar of your site’s posts') );
       		$this->WP_Widget('pgcalendar', __('PGCalendar'), $widget_ops);
       	}
   
       	function widget( $args, $instance ) {
       		extract($args);
       		$title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
       		echo $before_widget;
       		if ( $title )
       ```
   
 * and then I kept the original code from the default-widgets.php
 * and at the end of the file, I included:
 * `add_action('widgets_init', create_function('', 'return register_widget("WP_PoliGastro_Widget_Calendar");'));`
 *  [Corey Salzano](https://wordpress.org/support/users/salzano/)
 * (@salzano)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736889)
 * it’s the widget name in the constructor that needs changed in order to add options
   to one of the default widgets.
 * `$this->WP_Widget('widget-name' ...`
 * i don’t completely understand why. have you figured this out? changing this widget
   name in my plugin and pushing that out as an update will break the widget when
   the update is downloaded. this makes sense, because it technically becomes a 
   different widget. i’d like to know why i can’t add options to one of the default
   widgets. my solution right now is having two plugins, one that modifies the built-
   in default widget, and another that duplicates it with a bit more functionality.
 * thanks for your post.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Modifying widget functions within a theme’ is closed to new replies.

## Tags

 * [plug-ins](https://wordpress.org/support/topic-tag/plug-ins/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 11 replies
 * 3 participants
 * Last reply from: [Corey Salzano](https://wordpress.org/support/users/salzano/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/modifying-widget-functions-within-a-theme/#post-1736889)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
