Action hook 'dynamic_sidebar_before'

in WP Core File wp-includes/widgets.php at line 738

View Source

dynamic_sidebar_before

Action Hook
Description
Fires before widgets are rendered in a dynamic sidebar. Note: The action also fires for empty sidebars, and on both the front end and back end, including the Inactive Widgets sidebar on the Widgets screen.

Hook Information

File Location wp-includes/widgets.php View on GitHub
Hook Type Action
Line Number 738

Hook Parameters

Type Name Description
int|string $index Index, name, or ID of the dynamic sidebar.
bool $has_widgets Whether the sidebar is populated with widgets. Default true.

Usage Examples

Basic Usage
<?php
// Hook into dynamic_sidebar_before
add_action('dynamic_sidebar_before', 'my_custom_function', 10, 2);

function my_custom_function($index, $has_widgets) {
    // Your custom code here
}

Source Code Context

wp-includes/widgets.php:738 - How this hook is used in WordPress core
<?php
 733  	 *
 734  	 * @param int|string $index       Index, name, or ID of the dynamic sidebar.
 735  	 * @param bool       $has_widgets Whether the sidebar is populated with widgets.
 736  	 *                                Default true.
 737  	 */
 738  	do_action( 'dynamic_sidebar_before', $index, true );
 739  
 740  	if ( ! is_admin() && ! empty( $sidebar['before_sidebar'] ) ) {
 741  		echo $sidebar['before_sidebar'];
 742  	}
 743  

PHP Documentation

<?php
/**
	 * Fires before widgets are rendered in a dynamic sidebar.
	 *
	 * Note: The action also fires for empty sidebars, and on both the front end
	 * and back end, including the Inactive Widgets sidebar on the Widgets screen.
	 *
	 * @since 3.9.0
	 *
	 * @param int|string $index       Index, name, or ID of the dynamic sidebar.
	 * @param bool       $has_widgets Whether the sidebar is populated with widgets.
	 *                                Default true.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 2
  • File: wp-includes/widgets.php
Related Hooks

Related hooks will be displayed here in future updates.