This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Add search to functions.php?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Add search to functions.php?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #22469
    DSLMSDSLMS
    Participant

    Hello,

    My theme (TheGem) comes with a search icon in the main header nav.

    I’d like to replace this and all default search boxes on the site with the Ajax Search Pro version instead for these. The theme author has given me these instructions:
    Remove this from functions.php
    function thegem_menu_item_search($items, $args){
    if($args->theme_location == 'primary' && thegem_get_option('header_layout') !== 'overlay' && !thegem_get_option('hide_search_icon')) {
    $items .= '<li class="menu-item menu-item-search"><div class="minisearch"><form role="search" id="searchform" class="sf" action="'. esc_url( home_url( '/' ) ) .'" method="GET"><input id="searchform-input" class="sf-input" type="text" placeholder="'.esc_html__('Search...', 'thegem').'" name="s"><span class="sf-submit-icon"></span><input id="searchform-submit" class="sf-submit" type="submit" value=""></form></div>';
    }
    return $items;
    }
    add_filter('wp_nav_menu_items', 'thegem_menu_item_search', 10, 2);

    Then replace the filter with the new one in child functions.php

    But I’m not sure how to insert yours to replace it, any chance of some help please?

    Regards,
    Mike

    #22470
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    Well, based on the code and the instructions, then make sure to remove that previous code, and try this one instead:

    function asp_thegem_menu_item_search($items, $args){
        if($args->theme_location == 'primary' && thegem_get_option('header_layout') !== 'overlay' && !thegem_get_option('hide_search_icon')) {
            $items .= '<li class="menu-item menu-item-search">
              <div>'.do_shortcode('[wpdreams_ajaxsearchpro id=1]').'</div>
            </li>';
        }
        return $items;
    }
    add_filter('wp_nav_menu_items', 'asp_thegem_menu_item_search', 10, 2);

    I don’t know if this is going to work correctly as it should, as I cannot test this, but there is a chance that it might do the trick.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.