• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / is_active_widget() – Determines whether a given widget is displayed on the front end.

You appear to be a bot. Output may be restricted

Description

Determines whether a given widget is displayed on the front end.

Either $callback or $id_base can be used $id_base is the first argument when extending WP_Widget class Without the optional $widget_id parameter, returns the ID of the first sidebar in which the first instance of the widget with the given callback or $id_base is found. With the $widget_id parameter, returns the ID of the sidebar where the widget with that callback/$id_base AND that ID is found. NOTE: $widget_id and $id_base are the same for single widgets. To be effective this function has to run after widgets have initialized, at action init or later. For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook.

Usage

$string|false = is_active_widget( $callback, $widget_id, $id_base, $skip_inactive );

Parameters

$callback
( callable|false ) optional – Optional, Widget callback to check. Default false.
$widget_id
( int|false ) optional – Optional. Widget ID. Optional, but needed for checking. Default false.
$id_base
( string|false ) optional – Optional. The base ID of a widget created by extending WP_Widget. Default false.
$skip_inactive
( bool ) optional default: 1 – Optional. Whether to check in 'wp_inactive_widgets'. Default true.

Returns

string|false False if widget is not active or id of sidebar in which the widget is active.

Source

File name: wordpress/wp-includes/widgets.php
Lines:

1 to 24 of 24
function is_active_widget( $callback = false, $widget_id = false, $id_base = false, $skip_inactive = true ) {
  global $wp_registered_widgets;

  $sidebars_widgets = wp_get_sidebars_widgets();

  if ( is_array( $sidebars_widgets ) ) {
    foreach ( $sidebars_widgets as $sidebar => $widgets ) {
      if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) {
        continue;
      }

      if ( is_array( $widgets ) ) {
        foreach ( $widgets as $widget ) {
          if ( ( $callback && isset( $wp_registered_widgets[ $widget ]['callback'] ) && $wp_registered_widgets[ $widget ]['callback'] === $callback ) || ( $id_base && _get_widget_id_base( $widget ) === $id_base ) ) {
            if ( ! $widget_id || $widget_id === $wp_registered_widgets[ $widget ]['id'] ) {
              return $sidebar;
            }
          }
        }
      }
    }
  }
  return false;
}
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 2nd April 2020

Primary Sidebar

Information

Function name: is_active_widget
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/widgets.php
File ref: wp-includes/widgets.php
Deprecated?: No
API Letters: A,I,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites