This page contains the technical documentation for the WordPress
Widgets API and is written for developers. If you're not a developer you
may want to review the Widgets page.
In technical terms: a WordPress Widget is a PHP object that echoes string data to STDOUT when its widget() method is called. It's located in
To be effective this function has to run after widgets have initialized, at action 'init' or later.
In technical terms: a WordPress Widget is a PHP object that echoes string data to STDOUT when its widget() method is called. It's located in
wp-includes/widgets.php.Codex
Codex tools:
Log in
Function Reference/is active widget
Contents[hide] |
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.0Source File
is_active_widget() is located inwp-includes/widgets.php.