Issue when adding search form code to functions.php file
-
Hello,
I was really happy when I managed to add a search form to my main menu using the instructions on your site here https://www.themesandco.com/snippet/adding-an-html5-search-form-in-your-wordpress-menu/However, subsequently I had issues logging in to the admin area of WP. When I removed this code – and one previous to it – from the functions.php file in my child theme, all went back to normal.
I have probably missed something obvious here, but any ideas what?
// Exclude images from search results – Customizr
add_action(‘init’, function(){
remove_filter( ‘pre_get_posts’, array(TC_post_list::$instance, ‘tc_include_attachments_in_search’) );
});
// As of 3.1.10, Customizr doesn’t output an html5 form.
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’) )
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) . ”;
}
- The topic ‘Issue when adding search form code to functions.php file’ is closed to new replies.