How to add a search box to the WordPress menu?
Open the functions.php file and add the Copy and paste the code snippet below and save it. The following code will automatically add a search box to the main menu bar.
/** * Add searchbox in menubar */ add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 ); function add_search_box( $items, $args ) { $items .= ' <ul> <li>' . get_search_form( false ) . '</li> </ul> '; return $items; }
Related recommendations: "WordPress Tutorial"
By default, it will appear as a theme color combination, but if you want to change the style, you can customize the style Add to search box. In the example, I've added margins to the search box from the top and right.
.searchbox-position { margin-top: 15px; margin-right: 20px; }
The above is the detailed content of How to call the search box in WordPress. For more information, please follow other related articles on the PHP Chinese website!