- This topic has 7 replies, 2 voices, and was last updated 3 years, 6 months ago by Tom.
-
AuthorPosts
-
October 8, 2020 at 4:12 pm #1479364Ruben
Hello team,
I am using primary and secondary navigations for desktop and mobile header for mobile.
I moved both my search and my cart icons to the secondary menu. When switching to mobile header the search icon remains in place but not the cart. How can I keep also the cart?
Thank you.
Sorry I cannot share the url, I’m on a local server for testing.
October 9, 2020 at 9:12 am #1480691TomLead DeveloperLead DeveloperHi there,
How are you moving the icons to the secondary menu? Can you share your code?
Let us know π
October 9, 2020 at 9:50 am #1480768RubenHi Tom,
I’m doing it through the Snippets, with the code you guys suggest somewhere in the Documentation. I’m not much of a coder, so I might have done something wrong π
For Cart:
add_filter( 'generate_woocommerce_menu_item_location', 'tu_move_menu_cart_item' ); function tu_move_menu_cart_item() { return 'secondary'; }
For Search:
add_action( 'after_setup_theme', function() { remove_action( 'generate_inside_navigation', 'generate_navigation_search' ); remove_action( 'generate_inside_navigation', 'generate_mobile_menu_search_icon' ); add_action( 'generate_inside_secondary_navigation', 'generate_navigation_search' ); add_action( 'generate_inside_secondary_navigation', 'generate_mobile_menu_search_icon' ); remove_filter( 'wp_nav_menu_items', 'generate_menu_search_icon', 10, 2 ); } ); add_filter( 'wp_nav_menu_items', function( $nav, $args ) { $generate_settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_defaults() ); if ( 'enable' !== $generate_settings['nav_search'] ) { return $nav; } if ( 'secondary' === $args->theme_location ) { $icon = generate_get_svg_icon( 'search', true ); return $nav . '<li class="search-item" title="' . esc_attr_x( 'Search', 'submit button', 'generatepress' ) . '"><a href="#">' . $icon . '<span class="screen-reader-text">' . _x( 'Search', 'submit button', 'generatepress' ) . '</span></a></li>'; } return $nav; }, 10, 2 );
October 9, 2020 at 1:31 pm #1481103TomLead DeveloperLead DeveloperHave you switched to the flexbox version of the theme?
October 9, 2020 at 5:04 pm #1481256RubenYes, I started designing the web on v.3, so I guess it defaults to flexbox.
October 10, 2020 at 9:28 am #1482244TomLead DeveloperLead DeveloperJust tested this and it seems to be working:
add_filter( 'generate_woocommerce_menu_item_location', function() { return 'secondary'; } ); add_action( 'wp', function() { remove_action( 'generate_inside_navigation', 'generate_navigation_search' ); add_action( 'generate_inside_secondary_navigation', 'generate_navigation_search' ); if ( 'enable' === generate_get_option( 'nav_search' ) ) { remove_action( 'generate_menu_bar_items', 'generate_do_navigation_search_button' ); add_action( 'generate_secondary_menu_bar_items', 'generate_do_navigation_search_button' ); } }, 20 );
October 12, 2020 at 7:29 am #1484806RubenHi Tom,
It works. Thanks a lot!
October 12, 2020 at 9:28 am #1485198TomLead DeveloperLead DeveloperYou’re welcome π
-
AuthorPosts
- You must be logged in to reply to this topic.