Title: in_widget_form
Published: April 25, 2014
Last modified: April 28, 2025

---

# do_action_ref_array( ‘in_widget_form’, WP_Widget $widget, null $return, array $instance )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#wp--skip-link--target)

Fires at the end of the widget control form.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#description)󠁿

Use this hook to add extra fields to the widget form. The hook is only fired if 
the value passed to the ‘widget_form_callback’ hook is not false.

Note: If the widget has no form, the text echoed from the default form method can
be hidden using CSS.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#parameters)󠁿

 `$widget`[WP_Widget](https://developer.wordpress.org/reference/classes/wp_widget/)

The widget instance (passed by reference).

`$return`null

Return null if new fields are added.

`$instance`array

An array of the widget’s settings.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#source)󠁿

    ```php
    do_action_ref_array( 'in_widget_form', array( &$this, &$return, $instance ) );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-widget.php#L553)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-widget.php#L553-L553)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_REST_Widget_Types_Controller::get_widget_form()](https://developer.wordpress.org/reference/classes/wp_rest_widget_types_controller/get_widget_form/)`wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php` |

Returns the output of [WP_Widget::form()](https://developer.wordpress.org/reference/classes/wp_widget/form/) when called with the provided instance. Used by encode_form_data() to preview a widget’s form.

  | 
| [WP_Widget::form_callback()](https://developer.wordpress.org/reference/classes/wp_widget/form_callback/)`wp-includes/class-wp-widget.php` |

Generates the widget control form (Do NOT override).

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/in_widget_form/?output_format=md#comment-content-4291)
 2.   [Razon Komar Pal](https://profiles.wordpress.org/raazon/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/in_widget_form/#comment-4291)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fin_widget_form%2F%23comment-4291)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fin_widget_form%2F%23comment-4291)
 4. Add custom widget field end of the widgets control form.
 5.     ```php
        if ( ! function_exists( 'wpdocs_display_custom_field_in_widget_form' ) ) {
    
            add_action( 'in_widget_form', 'wpdocs_display_custom_field_in_widget_form', 10, 3 );
    
            /**
             * Append custom field end of the widgets control form
             * Fires at the end of the widget control form.
             */
            function wpdocs_display_custom_field_in_widget_form( $widget, $return, $instance ) {
                $column = isset( $instance['column'] ) ? $instance['column'] : '';
    
                ob_start();
                ?>
    
                <p>
                    <label for="<?php echo esc_attr( $widget->get_field_id( 'itclan_bs_grid_class' ) ) ?>"><?php _e( 'Column Label', 'text_domain' ) ?>
                        <input class="widefat" value="<?php echo esc_attr( $column ) ?>" id="<?php echo esc_attr( $widget->get_field_id( 'column' ) ) ?>" name="<?php echo esc_attr( $widget->get_field_name( 'column' ) ) ?>" type="text" />
                        <small><?php _e( 'Some additional description.', 'text_domain' ) ?></small>
                    </label>
                </p>
    
                <?php 
                echo ob_get_clean();
            }
        }
        ```
    
 6. Filter widget’s settings before saving. It will save our custom field `column` 
    data.
 7.     ```php
        if ( ! function_exists( 'wpdocs_update_custom_field_in_widget_form' ) ) {
    
            add_action( 'widget_update_callback', 'wpdocs_update_custom_field_in_widget_form', 10, 2 );
    
            /**
             * Update widget fields
             * Filters a widget’s settings before saving.
             */
            function wpdocs_update_custom_field_in_widget_form( $instance, $new_instance ) {
                $instance['column'] = ! empty( $new_instance['column'] ) ? $new_instance['column'] : '';
                return $instance;
            }
        }
        ```
    
 8.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fin_widget_form%2F%3Freplytocom%3D4291%23feedback-editor-4291)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fin_widget_form%2F)
before being able to contribute a note or feedback.