WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/is active widget

Contents

Description

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.

Usage

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

Parameters

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

Return Values

(mixed) 
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.

Examples

Only load a script when the widget is active

<?php
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.

Related

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.