You appear to be a bot. Output may be restricted
Description
Conditionally display a sidebar, wrapped in a div by default.
The $args array accepts the following keys:
– before
(markup to be displayed before the widget area output), – after
(markup to be displayed after the widget area output), – default
(fallback text if the sidebar is not found, or has no widgets, default is an empty string), – show_inactive
(flag to show inactive sidebars, default is false), – before_sidebar_hook
(hook that fires before the widget area output), – after_sidebar_hook
(hook that fires after the widget area output).
Return false early if the sidebar is not active and the show_inactive
argument is false.
Usage
$bool = genesis_widget_area( $id, $args );
Parameters
- $id
- ( string ) required – Sidebar ID, as per when it was registered.
- $args
- ( array ) optional – Arguments.
Returns
bool false
if $id
is falsy, or $args['show_inactive']
is falsy and sidebar is not currently being used. true
otherwise.
Source
File name: genesis/lib/functions/widgetize.php
Lines:
function genesis_widget_area( $id, $args = [] ) { if ( ! $id ) { return false; } $defaults = apply_filters( 'genesis_widget_area_defaults', [ 'before' => genesis_markup( [ 'open' => '<aside class="widget-area">' . genesis_sidebar_title( $id ), 'context' => 'widget-area-wrap', 'echo' => false, 'params' => [ 'id' => $id, ], ] ), 'after' => genesis_markup( [ 'close' => '</aside>', 'context' => 'widget-area-wrap', 'echo' => false, ] ), 'default' => '', 'show_inactive' => 0, 'before_sidebar_hook' => 'genesis_before_' . $id . '_widget_area', 'after_sidebar_hook' => 'genesis_after_' . $id . '_widget_area', ], $id, $args ); $args = wp_parse_args( $args, $defaults ); if ( ! $args['show_inactive'] && ! is_active_sidebar( $id ) ) { return false; } // Opening markup. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['before']; // Before hook. if ( $args['before_sidebar_hook'] ) { /** * Fires before widget area is output. * * Default format of hook name is 'genesis_before_' . $id . '_widget_area'`, where `$id` is the widget area * ID, but this can be changed when registering a new widget area. * * @since ??? */ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound do_action( $args['before_sidebar_hook'] ); } if ( ! dynamic_sidebar( $id ) ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['default']; } // After hook. if ( $args['after_sidebar_hook'] ) { /** * Fires before widget area is output. * * * Default format of hook name is 'genesis_after_' . $id . '_widget_area'`, where `$id` is the widget area * ID, but this can be changed when registering a new widget area. * * @since ??? */ do_action( $args['after_sidebar_hook'] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound } // Closing markup. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['after']; return true; }