Featured Video Play Icon

Adding Search Bar in WordPress Main Menu

WordPress Tutorial: In simple steps, going to show you how to add a search bar in the WordPress main menu. The following codes are tested by using WordPress Child Theme.

Step 1: Open functions.php file from the child theme.

Step 2: Add this below code

Adding Search Box in Main Menu
add_filter( 'wp_nav_menu_items', 'main_nav_search', 10, 2 );
function main_nav_search($items, $args){
    // if this isn't the primary menu, do nothing
    if( !( $args->theme_location == 'primary' ) )
        return $items;
    // Otherwise, add search form
    return $items . '<li>' . get_search_form(false) . '</li>';

Step 3: Save it and you are done.

Published by

Emdad Khan

I am Emdad – A wordpress lover. I do website development using wordpress as well as blogging. My wordpress blogs mainly for new wp lover who is interested to learn about wordpress and want to master on it. Keep exploring Bn Web Design.

Leave a Reply