Search Box

Hello,

Is there an easy way to add a search box beside the navigation pane in this theme?

Other than the standard WP widget of course.

Best regards,

Mark J

Dear Mark,

In order to achieve that objective, could you please try to do the following?

  1. Add the following function into the child theme’s functions.php file or you can use the Code Snippets plugin if you don’t want to create a child theme.

/**
 * Add search form on primary menu
 */
add_filter( 'wp_nav_menu_items', 'perth_child_add_top_search_menu', 10, 2 );
function perth_child_add_top_search_menu( $items, $args ) {
    if ($args->theme_location == 'primary') {
        $items .= '<li class="top-search-menu">'.get_search_form(false).'</li>';
    }
    return $items;
}

  1. Add the following CSS code through the Simple Custom CSS plugin or child theme’s style.css.

.top-search-menu:after{
  display: none;
}

.top-search-menu .search-submit{
  display: none;
}

@media only screen and (min-width:931px){
  .top-search-menu{
    margin-top: -13px;
  }
}
  

Regards,
Kharis

Hello Kharis,

Worked like a charm.

The only thing is the search button right beside the text box for some reason only appeared for a second then disappeared… would you know any reason for that?

Best regards,

Mark Jakobsen

Dear Mark,

Please remove these lines:


.top-search-menu .search-submit{
  display: none;
}

Regards,
Kharis

Thank you so much for your help.

Last problem is that through the search engine, it gives me various 404 errors when i click on certain posts (works on regular pages - but text from a plugin menu, and different posts it gives 404). I tried re-looking the perma-links on Wordpress. Is there anything else that could cause that?

Best regards,

Mark Jakobsen

Dear Mark,

So sorry for the delay. What keyword did you enter on Google search? Let me try it and inspect what might be causing the issue.

Regards,
Kharis

Hello,

No worries.

THe website is this: http://glutenfrizone.dk/

Try searching for “boller” and pick the first item. It is an item off the menu in “bageriet”. The text of it will show as you search, but as you click on it you’ll get a 404.

If it helps i’ve been using the plugin https://wordpress.org/support/plugin/quick-restaurant-menu/ to make the menu’s.

Best regards,

Mark Jakobsen

Dear Mark,

Try to flush your site’s permalink by doing the following:

Dashboard > Settings > Permalinks > just hit the “Save Changes” button. If it doesn’t helps, there might be a problem with the .htaccess file which can’t be created/updated due to permissions config of your root folder. Please see the WordPress Codex.

Regards,
Kharis

Thank you so much for your help i got the search box done which was the point of the topic.

It seems the problem is with the .htacess file as refreshing the permalinks isn’t working.

Best regards,

Mark Jakobsen