storefront/inc/storefront-menu-functions.php
Niels Lange 26583788de
Add support for menu description. (#1771)
* Add support for menu description.

* Remove version number from menu description function

* Update menu item description styles

* Make nav menu description and cart icon product count text contrast WCAG 2.0 AA compliant

contrast was ~2.5, target is 4.5+

Co-authored-by: Tomasz Tunik <tomasztunik@gmail.com>
2022-03-22 13:44:28 +01:00

25 lines
827 B
PHP

<?php
/**
* Storefront menu functions.
*
* @package storefront
*/
/**
* Filters the arguments for a single nav menu item.
*
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
*
* @return stdClass
*/
function storefront_add_menu_description_args( $args, $item, $depth ) {
$args->link_after = '';
if ( 0 === $depth && isset( $item->description ) && $item->description ) {
// The extra <span> element is here for styling purposes: Allows the description to not be underlined on hover.
$args->link_after = '<p class="menu-item-description"><span>' . $item->description . '</span></p>';
}
return $args;
}
add_filter( 'nav_menu_item_args', 'storefront_add_menu_description_args', 10, 3 );