Title: &quot;widget&quot; function not being called
Last modified: August 20, 2016

---

# "widget" function not being called

 *  [yongke](https://wordpress.org/support/users/yongke/)
 * (@yongke)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/widget-function-not-being-called/)
 * I created a custom plugin/widget following tutorial instruction. It shows up 
   fine in control panel, but when I add it to the “Primary Widget Area”, it doesn’t
   show up. The rendering function “widget” is not being called. Is there any thing
   I need to do to enable it?
 *     ```
       class CustomWidget extends WP_Widget{
         /**
          * Declares our class.
          *
          */
         function CustomWidget(){
           $widget_ops = array('classname' => '_custom_widget', 'description' => __( "Custom Widget for Food") );
           $control_ops = array('width' => 250, 'height' => 400, 'id_base' => '-custom-widget');
           $this->WP_Widget('CustomWidget', ' Custom Widget', $widget_ops, $control_ops);
         }
   
         /**
          * Displays the Widget
          *
          */
         function widget($args, $instance){
             die;
           extract($args);
           $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
           $menu_order = $instance['menu_order'];
           $show_siblings = $instance['show_siblings'];
           $exclude = $instance['exclude'];
           echo $before_widget;
           echo $before_title;
           echo 'Title!!!';
           echo $after_title;
           echo 'Content!!!';
           echo $after_widget;
         }
   
         /**
          * Saves the widget's settings.
          *
          */
         function update($new_instance, $old_instance){
           $instance = $old_instance;
           $instance['title'] = strip_tags($new_instance['title']);
           return $instance;
         }
   
         /**
          * Creates the edit form for the widget.
          *
          */
         function form($instance){
   
           //Defaults
           $instance = wp_parse_args( (array) $instance, array('title'=>'', 'lineOne'=>'Hello', 'lineTwo'=>'World') );
   
           $title = htmlspecialchars($instance['title']);
           $menu_order = htmlspecialchars($instance['menu_order']);
           $show_siblings = htmlspecialchars($instance['show_siblings']);
           $exclude = htmlspecialchars($instance['exclude']);
   
           echo 'No options yet<BR><BR>';
         }
   
       }
   
       add_action( 'widgets_init', create_function( '', 'register_widget("CustomWidget");' ) );
       ```
   

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

 *  [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * (@big-bagel)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/widget-function-not-being-called/#post-2391434)
 * There seems to be an errant `die;` at the beginning of the `widget` function.
 *  Thread Starter [yongke](https://wordpress.org/support/users/yongke/)
 * (@yongke)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/widget-function-not-being-called/#post-2391435)
 * Eh yea, I added it to see if it dies. It doesn’t. So the function isn’t being
   hit.
 *  [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * (@big-bagel)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/widget-function-not-being-called/#post-2391451)
 * I tracked the problem down to `id-base` in your control options. If your take
   out the hyphens (`'id-base' => 'customwidget'`) or just leave out your custom
   control options all together:
 *     ```
       function CustomWidget() {
           $widget_ops = array( 'classname' => '_custom_widget', 'description' => 'Custom Widget for Food' );
   
           $this->WP_Widget( 'CustomWidget', ' Custom Widget', $widget_ops );
       }
       ```
   
 * Then everything seems to be happy.
 *  Thread Starter [yongke](https://wordpress.org/support/users/yongke/)
 * (@yongke)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/widget-function-not-being-called/#post-2391452)
 * Thanks! I will check it out.
 *  [OS1](https://wordpress.org/support/users/os1/)
 * (@os1)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/widget-function-not-being-called/#post-2391594)
 * Has anyone found a solution to this? It seems very bizarre but the widget() routine
   gets called AFTER the page had rendered in the browser. This seems to happen 
   as a matter of course for widgets that work. widget() is called while the HTML
   is being returned to the browser and then once afterwards! For these widgets 
   that don’t work there is one call made to widget() and it is after the page content
   has already been sent to the browser. Why do some widgets work and some not when,
   on the surface, there is no difference in the code structure?! Is this a WP bug
   and has it been reported?
 *  [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * (@big-bagel)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/widget-function-not-being-called/#post-2391595)
 * [@os1](https://wordpress.org/support/users/os1/):
 * Since the OP hasn’t said anything in a couple weeks, I would assume his issue
   was resolved. The problem here was with what `id_base` was set to. It would be
   best to start another topic specific to your question(s).

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

The topic ‘"widget" function not being called’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 6 replies
 * 3 participants
 * Last reply from: [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/widget-function-not-being-called/#post-2391595)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
