Mobile menu parent link on xstore theme with elementor

11 replies3 participantsUpdated by Luca Rossi

XStore documentationXStore mobile header and mobile menu
  • Avatar: 2347281
    2347281
    Participant

    Good evening, there is a website using the XStore theme and Elementor. Question: Is it possible to enable links for parent categories in the mobile menu? Right now, only the sub-menu opens, and it’s not possible to access the main category.

    Please, contact administrator
    for this information.

    11 Answers

    Avatar: 2347281
    2347281
    Participant

    and one more: in lightbox apears some line “data-e-action-hash=”

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff

    Dear @2347281,

    Please try adding this custom code under functions.php file locates in your child theme:

    
    add_action('wp_footer', 'n2t_wp_footer');
    function n2t_wp_footer() {
        ?>
        <script>
            jQuery((document).on('click touchend', '.etheme-elementor-nav-menu.vertical li a.item-link.etheme-elementor-nav-menu-item.etheme-elementor-nav-menu-item-parent', function (e){
                window.location.href = jQuery(this).attr('href');
            });
    
            jQuery(document).on('click touchend', '.etheme-elementor-nav-menu.vertical li a.item-link.etheme-elementor-nav-menu-item.etheme-elementor-nav-menu-item-parent span.etheme-elementor-nav-menu-item-arrow', function (e){
                var parent = jQuery(this).parent().parent();
                console.log(parent);
                jQuery(parent).next('.nav-sublist-dropdown').slideToggle();
                return false;
            });)
        </script>
        <?php
    }
    

    and one more: in lightbox apears some line “data-e-action-hash=”

    Please provide the product URL.

    Thank you!

    Avatar: Hassan
    Hassan
    Participant

    Hello,

    Did this solution work?

    I have the same problem with parent link on mobile menu.

    Thanks

    Avatar: 2347281
    2347281
    Participant

    no,

    i wrote my solution:

    function xstore_modify_menu_items($items) {
        foreach ($items as &$item) {
            if (in_array('menu-item-has-children', $item->classes)) {
                $item->title = '<span class="has-submenu">' . $item->title . '</span>';
            }
        }
        return $items;
    }
    add_filter('wp_nav_menu_objects', 'xstore_modify_menu_items');
    
    function enqueue_custom_mobile_menu_script() {
        wp_enqueue_script(
            'custom-mobile-menu',
            get_stylesheet_directory_uri() . '/js/mobile-menu.js', 
            array('jquery'), 
            filemtime(get_stylesheet_directory() . '/js/mobile-menu.js'), 
            true 
        );
    }
    add_action('wp_enqueue_scripts', 'enqueue_custom_mobile_menu_script');

    now toggle opens dropdown, o category click opens category

    Avatar: Hassan
    Hassan
    Participant

    Did you put this in the themes function.php file?

    thanks

    Avatar: 2347281
    2347281
    Participant

    yep

    Avatar: Hassan
    Hassan
    Participant

    Thanks for the solution, but it didn’t work for me.

    I added it to the functions.php file and cleared the cache, but the links are still not clickable.

    I’ve switched to using the Elementor header instead of the native XStore theme header. Maybe that is why the code didnt work.

    Avatar: 2347281
    2347281
    Participant

    i’m on elementor too, should work, try on new device, it may be browser cache left

    Avatar: Justin
    Luca Rossi
    Support staff

    Dear @Hassan,

    We kindly request you to create a separate support ticket and provide the URL of your website along with the administrator account details.

    Our team will be happy to assist you in debugging the custom codes.

    Thanks for sharing a solution @2347281!

    Best regards,
    8Theme Team

    Avatar: 2347281
    2347281
    Participant

    @Hassan , I completely forgot and missed this: with the code we’re adding to functions.php, we’re also including a .js script. Please create a file named mobile-menu.js with the following code:

    document.addEventListener("DOMContentLoaded", function () {
        const menuItems = document.querySelectorAll(".menu-item-has-children > a, .has-submenu");
    
        menuItems.forEach((menuItem) => {
            menuItem.addEventListener("click", function (e) {
                const parentItem = this.closest(".menu-item-has-children");
    
                if (!parentItem.classList.contains("submenu-open")) {
                    e.preventDefault(); 
                    parentItem.classList.add("submenu-open");
                } else {
                    window.location.href = this.closest("a").href; 
                }
            });
        });
    });
    

    and place it in the theme folder so that the path is:
    xstore-child/js/mobile-menu.js

    Avatar: Justin
    Luca Rossi
    Support staff

    Thanks for sharing @2347281!


    @Hassan
    you can also use this plugin to insert the custom codes: https://wordpress.org/plugins/code-snippets/.

    Best Regards,
    8Theme’s Team

Want to reply? Log in, or register with your ThemeForest purchase code, to reply to this topic.

Login / Register