Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #945368

    Hi guys,

    I’m working on a website and I’m trying to add a search bar inside the burger menu. I’ve tried to use this code:

    add_filter( ‘wp_nav_menu_items’, ‘avf_add_search’, 3, 2 );
    function avf_add_search( $items, $args ) {
    if ($args->theme_location == ‘avia’)
    {
    $search = ‘<li id=”menu-item-search-mobile” class=”menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-18 current_page_item menu-item-top-//level menu-item-top-level-5″>’.get_search_form(false).’‘;
    $items = $search . $items;
    }
    return $items;
    }

    Yet, I had no luck with it.

    The thing is, I’m also using an AMP plugin on this website and I want to match the 2 menus as much as possible. Because of that, I need to add that search at the bottom of the menu.

    Also, if there’s a way to hide the search icon only when the menu is open, that would be awesome.

    #946362

    Hey StartSmallDigital,

    Thank you for using Enfold.

    This is the updated script. It will append a placeholder for the search form and then the script will append the search field once the mobile menu is clicked.

    // https://kriesi.at/support/topic/search-in-mobile-hamburger-menu/#post-943960

    Best regards,
    Ismael

    #947228

    Thank you Ismael. :D

    That code works. Yet, is there any way to add the search bar after the menu links?

    And hide the search icon near the x once the burger opens?

    #948331

    Hi,

    Would you mind providing a precise link to the page, showing the elements in question? We need to be able to inspect them in order to help :)

    Best regards,
    Vinay

    #953384

    Hi Guys,

    Sorry for the late answer. This project was put on hold a little while

    In order to better understand what I’m talking about please go to this article:

    and the AMP version:
    https://elitaromaniei.ro/crema-sportului-romanesc-in-2018/?amp

    In mobile view, look at the search bars inside the menus.
    I have uploaded a side by side print screen here: https://ibb.co/n26DR7

    I want to make the right side look the same as the left one.

    Cheers

    #954273

    Hi StartSmallDigital,

    Here is the code you can put in Enfold > General Styling > Quick Css,  if it does not work, put into themes/enfold/css/custom.css

    
    @media only screen and (max-width: 767px) {
        .html_av-overlay-side #top .av-burger-overlay li.menu-item-search-mobile.av-active-burger-items {
            margin-top: 20px;
        }
    
        .menu-item-search-mobile.av-active-burger-items form > div {
            width: 80%;
            margin: 0 auto;
        }
        #top #searchsubmit {
            width: 40px;
            right: 50px;
            border-radius: 30px;
            background: yellow;
            color: navy;
            font-size: 14px;
        }
        #top #s {
            padding: 7px 0 7px 10px;
            background: yellow !important;
            border-radius: 30px;
        }
       
    }
    

    If you need further assistance please let us know.

    Best regards,
    Victoria

    #958536

    Hi Victoria, that code is awesome. It really helped.

    Still, the search is still above the menu links. Any way I can make the search to be the last item in the menu?
    I use this code for the search bar:
    // Add search bar in menu
    add_filter( ‘wp_nav_menu_items’, ‘avf_add_search’, 9999, 2 );
    function avf_add_search( $items, $args ) {
    if ($args->theme_location == ‘avia’)
    {
    $search = ‘<li id=”menu-item-search-mobile” class=”menu-item”>‘;
    $items = $search . $items;
    }
    return $items;
    }
    add_action(‘wp_footer’, ‘avf_add_search_script’);
    function avf_add_search_script(){
    ?>
    <script type=”text/javascript”>
    (function($) {
    $(‘.av-burger-menu-main’).on(‘click’, function() {
    var page = window.location.href;
    var mobile = $(‘.menu-item-search-mobile’);
    var search = ‘<form action=”‘+page+'” method=”get” class=””><div><input type=”submit” value=”” id=”searchsubmit” class=”button avia-font-entypo-fontello”><input type=”text” id=”s” name=”s” value=”” placeholder=”Search”></div></form>’;

    setTimeout(function() {
    if(mobile.find(‘form’).length == 1) return;
    mobile.html(search);
    }, 500);
    });
    })(jQuery);
    </script>
    <?php
    }

    #959604

    Hi StartSmallDigital,

    Looks fine on my end
    Image 2018-05-21 at 10.57.40.png

    Is this not what you’re looking for?

    Best regards,
    Victoria

    #959809

    Hey Victoria,
    That’s how it looks on the AMP version. On the Enfold version, the search bar is above the menu, and I need to drag it down under it.

    #960038

    Hi,

    I am afraid you’ll need to contact the plugin author for more info about the issue. Making third-party plugins compatible with the theme is unfortunately beyond the support scope we offer. Sorry for that!

    Best regards,
    Basilis

    #967310

    Hi Basilis, I don’t need to change the plugin, but the enfold code I got from this forum.

    The Enfold search form needs to be under the Enfold mobile menu. No need to edit the AMP version

    #969863

    Hi,

    Thanks for the update.

    I couldn’t see the search bar inside the mobile menu container. Did you remove the script?

    Best regards,
    Ismael+

    #971396

    Hey Ismael,
    Yea, we eventually removed the search bar.
    Thank you.

    #971557

    Hi,

    Thanks for the update. I’m not sure if you still need some help with this though. Please feel free open a new thread. We’ll close this one for now. :)

    Best regards,
    Ismael

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Search bar inside burget menu’ is closed to new replies.