';
$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 = blog_tale_toggle_duration();
// Add the sub menu toggle.
$args->after .= '';
}
// Close the wrapper.
$args->after .= '
';
// Add sub menu icons to the primary menu without toggles.
} elseif ( 'primary-menu' === $args->theme_location ) {
if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
$args->after = '';
} else {
$args->after = '';
}
}
return $args;
}
add_filter( 'nav_menu_item_args', 'blog_tale_add_sub_toggles_to_main_menu', 10, 3 );
/**
* Displays SVG icons in social links menu.
*
* @since Blog Tale 1.0
*
* @param string $item_output The menu item's starting HTML output.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of the menu. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @return string The menu item output with social icon.
*/
function blog_tale_nav_menu_social_icons( $item_output, $item, $depth, $args ) {
// Change SVG icon inside social links menu if there is supported URL.
if ( 'social-menu' === $args->theme_location ) {
$svg = BlogTale_SVG_Icons::get_social_link_svg( $item->url );
if ( empty( $svg ) ) {
$svg = blog_tale_get_theme_svg( 'link' );
}
$item_output = str_replace( $args->link_after, '' . $svg, $item_output );
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'blog_tale_nav_menu_social_icons', 10, 4 );
/**
* Toggles animation duration in milliseconds.
*
* @since Blog Tale 1.0
*
* @return int Duration in milliseconds
*/
function blog_tale_toggle_duration() {
/**
* Filters the animation duration/speed used usually for submenu toggles.
*
* @since Blog Tale 1.0
*
* @param int $duration Duration in milliseconds.
*/
$duration = apply_filters( 'blog_tale_toggle_duration', 250 );
return $duration;
}