Modify wp_nav_menu arguments.
This function converts the wp_nav_menu to UIKit format. It uses Beans custom walker and also makes use of the Beans HTML API.
beans_modify_menu_args( array $args )
Return: (array) The modified wp_nav_menu arguments.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
$args | array | true | - | The wp_nav_menu arguments. |
Source
function beans_modify_menu_args( $args ) {
// Get type.
$type = beans_get( 'beans_type', $args );
// Check if the menu is in a widget area and set the type accordingly if it is defined.
if ( $widget_area_type = beans_get_widget_area( 'beans_type' ) ) {
$type = ( 'stack' == $widget_area_type ) ? 'sidenav' : $widget_area_type;
}
// Stop if it isn't a beans menu.
if ( ! $type ) {
return $args;
}
// Default item wrap attributes.
$attr = array(
'id' => '%1$s',
'class' => array( beans_get( 'menu_class', $args ) ),
);
// Add UIKit navbar item wrap attributes.
if ( 'navbar' == $type ) {
$attr['class'][] = 'uk-navbar-nav';
}
// Add UIKit sidenav item wrap attributes.
if ( 'sidenav' == $type ) {
$attr['class'][] = 'uk-nav uk-nav-parent-icon uk-nav-side';
$attr['data-uk-nav'] = '{multiple:true}';
}
// Add UIKit offcanvas item wrap attributes.
if ( 'offcanvas' == $type ) {
$attr['class'][] = 'uk-nav uk-nav-parent-icon uk-nav-offcanvas';
$attr['data-uk-nav'] = '{multiple:true}';
}
// Implode to avoid empty spaces.
$attr['class'] = implode( ' ', array_filter( $attr['class'] ) );
// Set to null if empty to avoid outputing empty class html attribute.
if ( ! $attr['class'] ) {
$attr['class'] = null;
}
$location_subfilter = ( $location = beans_get( 'theme_location', $args ) ) ? "[_{$location}]" : null;
// Force beans menu arguments.
$force = array(
'beans_type' => $type,
'items_wrap' => beans_open_markup( "beans_menu[_{$type}]{$location_subfilter}", 'ul', $attr, $args ) . '%3$s' . beans_close_markup( "beans_menu[_{$type}]{$location_subfilter}", 'ul', $args ),
);
// Allow walker overwrite.
if ( ! beans_get( 'walker', $args ) ) {
$args['walker'] = new _Beans_Walker_Nav_Menu;
}
// Adapt level to walker depth.
$force['beans_start_level'] = ( $level = beans_get( 'beans_start_level', $args ) ) ? ( $level - 1 ) : 0;
return array_merge( $args, $force );
}