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

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / twentytwenty_add_sub_toggles_to_main_menu() – Add a Sub Nav Toggle to the Expanded Menu and Mobile Menu.

You appear to be a bot. Output may be restricted

Description

Adds a Sub Nav Toggle to the Expanded Menu and Mobile Menu.

Usage

$stdClass = twentytwenty_add_sub_toggles_to_main_menu( $args, $item, $depth );

Parameters

$args
( stdClass ) required – An object of wp_nav_menu() arguments.
$item
( WP_Post ) required – Menu item data object.
$depth
( int ) required – Depth of menu item. Used for padding.

Returns

stdClass An object of wp_nav_menu() arguments.

Source

File name: twentytwenty/inc/template-tags.php
Lines:

1 to 35 of 35
function twentytwenty_add_sub_toggles_to_main_menu( $args, $item, $depth ) {

  // Add sub menu toggles to the Expanded Menu with toggles.
  if ( isset( $args->show_toggles ) && $args->show_toggles ) {

    // Wrap the menu item link contents in a div, used for positioning.
    $args->before = '<div class="ancestor-wrapper">';
    $args->after  = '';

    // Add a toggle to items with children.
    if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {

      $toggle_target_string = '.menu-modal .menu-item-' . $item->ID . ' > .sub-menu';
      $toggle_duration      = twentytwenty_toggle_duration();

      // Add the sub menu toggle.
      $args->after .= '<button class="toggle sub-menu-toggle fill-children-current-color" data-toggle-target="' . $toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="' . absint( $toggle_duration ) . '" aria-expanded="false"><span class="screen-reader-text">' . __( 'Show sub menu', 'twentytwenty' ) . '</span>' . twentytwenty_get_theme_svg( 'chevron-down' ) . '</button>';

    }

    // Close the wrapper.
    $args->after .= '</div><!-- .ancestor-wrapper -->';

    // Add sub menu icons to the primary menu without toggles.
  } elseif ( 'primary' === $args->theme_location ) {
    if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
      $args->after = '<span class="icon"></span>';
    } else {
      $args->after = '';
    }
  }

  return $args;

}
 

 View on GitHub View on Trac

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

Primary Sidebar

Information

Function name: twentytwenty_add_sub_toggles_to_main_menu
Plugin ref: Twenty Twenty
Version: 1.6
Sourcefile: inc/template-tags.php
File ref: inc/template-tags.php
Deprecated?: No
API Letters: A,S,T

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 5.6. PHP: 7.3.26
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:  wp-a2z.org
© Copyright WordPress a2z 2014-2021. All rights reserved.


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

  • Home
  • Blog
  • Sitemap
  • Sites