I'm creating a child theme and uikit's nav.min.js is interfering with my navigation. Is there easy way to only remove nav.min.js from uikit? File is located at /lib/api/src/js/core/.
Thanks!
Might this be it? In functions.php:
beans_add_smart_action( 'beans_uikit_enqueue_scripts', 'dequeue_assets' );
function dequeue_assets() {
beans_uikit_dequeue_components( array( 'nav' ) );
}
Tried this and worked but I decided to use nav.js anyways. When I removed that file, all my submenu items stayed open. I wanted to have submenu to remain open when they are active. Currently if you select submenu item, submenu doesn't stay open. Does anyone have solution for this? I want submenu to remain open when active. I'm using it as sidebar menu, not top dropdown.
Thanks in advance.
I asked a similar question not too long ago. My solution was to create walker, which I'm still in the process of writing.
Please check my post - is this the same as what you're trying to do?
That's excatly what I'm trying to do. Any success? Any chance you can share your walker script?
Here is what I have so far:
<?php
// force layout - meny will not display without this
add_filter( 'beans_layout', 'services_force_layout' );
function services_force_layout() {
return 'c_sp';
}
// walker for menu that expands parent of active child
class Walker_Service_Menu extends Walker_Nav_Menu {
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent\n<ul role=\"menu\" class=\"uk-nav-sub\">\n";
}
public function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent</ul>";
}
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
// set up classes for menu items
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
if ( $args->has_children )
$class_names .= ' uk-parent';
if ( in_array( 'current-menu-item', $classes ) || in_array( 'current-menu-parent', $classes ) )
$class_names .= ' uk-active';
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '<li' . $id . $value . $class_names . $dropdown . '>';
// set up attributes for menu items
$atts = array();
$atts['title'] = ! empty( $item->title ) ? $item->title : '';
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
$atts['class'] = 'uk-link';
if ( $args->has_children && $depth === 0 ) {
$atts['href'] = '#';
} else {
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
}
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
// build menu items
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
if ( ! $element )
return;
$id_field = $this->db_fields['id'];
if ( is_object( $args[0] ) )
$args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] );
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
}
// register sidebar for Services
add_action( 'widgets_init', 'register_sidebar_widget_area' );
function register_sidebar_widget_area() {
beans_register_widget_area( array(
'name' => 'Services Sidebar',
'id' => 'services_sidebar'
) );
}
// put menu into sidebar
beans_modify_action_callback( 'beans_widget_area_sidebar_primary', 'load_services_menu' );
function load_services_menu() {
wp_nav_menu( array(
'menu' => 'Services',
'menu_class' => '',
'container' => 'ul',
'items_wrap' => '<ul class="uk-nav uk-nav-parent-icon gs-services-sidebar" data-uk-nav>%3$s</ul>', // if you want sticky, put data-uk-sticky here
'theme_location' => beans_widget_area( 'services_sidebar' ),
'walker' => new Walker_Service_Menu(),
) );
}
Full credit to the fellow I referenced in my other post. You should also read this previous discussion: https://community.getbeans.io/discussion/force-layout-with-custom-sidebar/.
Awesome, after cleaning stuff I don't need, it worked.