Codex

Attention Help us to improve the Codex by filling out our documentation survey!

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

Conditional Tags: comments_open(), is_404(), is_admin(), is_admin_bar_showing(), is_archive(), is_attachment(), is_author(), is_category(), is_comments_popup(), is_date(), is_day(), is_feed(), is_front_page(), is_home(), is_local_attachment(), is_multi_author, is_month(), is_new_day(), is_page(), is_page_template(), is_paged(), is_plugin_active(), is_plugin_active_for_network(), is_plugin_inactive(), is_plugin_page(), is_post_type_archive(), is_preview(), is_search(), is_single(), is_singular(), is_sticky(), is_tag(), is_tax(), is_taxonomy_hierarchical(), is_time(), is_trackback(), is_year(), in_category(), in_the_loop(), is_active_sidebar(), is_active_widget(), is_blog_installed(), is_rtl(), is_dynamic_sidebar(), is_user_logged_in(), has_excerpt(), has_post_thumbnail(), has_tag(), pings_open(), email exists(), post_type_exists(), taxonomy_exists(), term_exists(), username exists(), wp_attachment_is_image(), wp_script_is()

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