Following conditional tag usually use in this filter function, wp_nav_menu_items
if( $args->theme_location == 'primary' )
if( $args->theme_location == 'secondary' )
if( $args->theme_location == 'primary' )
For an example, I want to add search box to Primary Menu in WPZOOM theme name Videozoom. Conditional tag above make sure the search only show in a specif menu (Primary)
1. Open functions.php
2. Add following code to functions
add_filter('wp_nav_menu_items','search_box_function', 10, 2); function search_box_function( $nav, $args ) { if( $args->theme_location == 'primary' ) return $nav."<li class='menu-header-search'><form role='search' action='".get_bloginfo('url')."' id='searchform' method='get'><input id="s" type="text" name="s" placeholder="Search" /><input id="searchsubmit" type="submit" value="Search" />"; return $nav; }
Leave a Reply