• I’m attempting to add the navigation toggle to my WordPress theme (iTheme’s “Herschel” theme, which does not usually have a search function in the navigation/logo header). I’ve looked through many of the tutorials but for some reason can’t get this seemingly simple feature to work.

    I’ve added the following php to my function.php file:

    add_theme_support( 'html5', array( 'search-form' ) );
    add_filter('wp_nav_menu_items', 'add_search_form_to_menu', 10, 2);
    function add_search_form_to_menu($items, $args) {
      // If this isn't the main navbar menu, do nothing
      if( !($args->theme_location == 'main') ) // with Customizr Pro 1.2+ and Cusomizr 3.4+ you can chose to display the saerch box to the secondary menu, just replacing 'main' with 'secondary'
        return $items;
      // On main menu: put styling around search and append it to the menu items
      return $items . '<li class="my-nav-menu-search">' . get_search_form(false) . '</li>';
    }

    And I’ve also added the CSS that was offering in a tutorial.

    According to the tutorial I’m using, *This adds a search form to your WordPress main menu. Once you’ve added this code, you can refresh your page and you’ll see a search form.* (Tutorial here, there are many I’ve looked through, this is just the one in particular that hasn’t given me php errors). No search shows up, but I’m not getting any errors in the console that appear to relate to the custom function.

    Any help would be much appreciated. I know enough php to get by but I’m afraid past basic Googling, I don’t know enough to troubleshoot something like this.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Navigation Toggle not working?’ is closed to new replies.