Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/is active widget


This Conditional Tag checks whether widget is displayed on the front-end.

To be effective this function has to run after widgets have initialized, at action 'init' or later.


 <?php is_active_widget$callback$widget_id$id_base$skip_inactive ); ?> 


(string) (optional) Widget callback to check.
Default: False
(int) (optional) Widget ID. Needed for checking.
Default: None
(string) (optional) Base ID of a widget created by extending WP_Widget.
Default: None
(boolean) (optional) Whether to check in 'wp_inactive_widgets'.
Default: True

Return Values

Returns false if the specified widget is not active, or the id of the sidebar in which the widget is active. If the callback is non-unique you can optionally specify the ID of the widget.


Only load a script when the widget is active

if ( is_active_widget( false, false, $this->id_base, true ) ) {
	wp_enqueue_script( 'jquery' );

Change Log

Since: 2.2.0

Source File

is_active_widget() is located in wp-includes/widgets.php.


Widgets: is_active_widget(), the_widget(), register_widget(), unregister_widget(), wp_register_widget_control(), wp_unregister_widget_control(), wp_convert_widget_settings(), wp_get_widget_defaults(), wp_widget_description()

See also index of Function Reference and index of Template Tags.