astra_dropdown_icon_to_menu_link( string $title, WP_Post $item, stdClass $args, int $depth )

Add dropdown icon if menu item has children.


Description


Parameters

$title

(string) (Required) The menu item title.

$item

(WP_Post) (Required) All of our menu item data.

$args

(stdClass) (Required) All of our menu item args.

$depth

(int) (Required) Depth of menu item.


Return

(string) The menu item.


Source

File: inc/extras.php

function astra_dropdown_icon_to_menu_link( $title, $item, $args, $depth ) {
	$role     = 'presentation';
	$tabindex = '0';
	$icon     = '';

	/**
	 * These menus are not overriden by the 'Astra_Custom_Nav_Walker' class present in Addon - Nav Menu module.
	 *
	 * Hence skipping these menus from getting overriden by blank SVG Icons and adding the icons from theme.
	 *
	 * @since 3.3.0
	 */
	$astra_menu_locations = array(
		'ast-hf-menu-1',        // Builder - Primary menu.
		'ast-hf-menu-2',        // Builder - Secondary menu.
		'ast-hf-menu-3',
		'ast-hf-menu-4',
		'ast-hf-menu-5',
		'ast-hf-menu-6',
		'ast-hf-menu-7',
		'ast-hf-menu-8',
		'ast-hf-menu-9',
		'ast-hf-menu-10',       // Cloned builder menus.
		'ast-hf-mobile-menu',   // Builder - Mobile Menu.
		'ast-hf-account-menu',  // Builder - Login Account Menu.
		'primary-menu',         // Old header - Primary Menu.
		'above_header-menu',    // Old header - Above Menu.
		'below_header-menu',    // Old header - Below Menu.
	);

	$load_svg_menu_icons = false;

	if ( defined( 'ASTRA_EXT_VER' ) ) {
		// Check whether Astra Pro is active + Nav menu addon is deactivate + menu registered by Astra only.
		if ( ! Astra_Ext_Extension::is_active( 'nav-menu' ) && in_array( $args->menu_id, $astra_menu_locations ) ) {
			$load_svg_menu_icons = true;
		}
	} else {
		// Check menu registered by Astra only.
		if ( in_array( $args->menu_id, $astra_menu_locations ) ) {
			$load_svg_menu_icons = true;
		}
	}

	if ( $load_svg_menu_icons ) {
		// Assign icons to only those menu which are registered by Astra.
		$icon = Astra_Icons::get_icons( 'arrow' );
	}
	foreach ( $item->classes as $value ) {
		if ( 'menu-item-has-children' === $value ) {
			$title = $title . '<span role="' . esc_attr( $role ) . '" class="dropdown-menu-toggle" tabindex="' . esc_attr( $tabindex ) . '" >' . $icon . '</span>';
		}
	}
	if ( 0 < $depth ) {
		$title = $icon . $title;
	}
	return $title;
}

Changelog

Changelog
Version Description
3.3.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.