• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Genesis Theme Framework a2z

Genesis Theme Framework a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / genesis_widget_area() – Conditionally display a sidebar, wrapped in a div by default.

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:

1 to 87 of 87
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;

}
 

Published: 25th November 2019 | Last updated: 25th November 2019

Primary Sidebar

Information

Function name: genesis_widget_area
Plugin ref: Genesis Framework
Version: 3.3.5
Sourcefile: lib/functions/widgetize.php
File ref: lib/functions/widgetize.php
Deprecated?: No
API Letters: A,G,W

Footer

Genesis a2z
Genesis Theme Framework a2z
WordPress Dynamic API Reference
WordPress 5.9.3
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:  genesis.wp-a2z.org
© Copyright Genesis a2z 2014-2022. All rights reserved.


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

  • Home
  • Blog
  • Sitemap
  • Sites