Home > CMS Tutorial > WordPress > How to call the search box in WordPress

How to call the search box in WordPress

爱喝马黛茶的安东尼
Release: 2019-07-20 15:36:11
Original
5336 people have browsed it

How to call the search box in WordPress

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>&#39; . get_search_form( false ) . &#39;</li>
</ul>
&#39;;
return $items;
}
Copy after login

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;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template