Last active
August 29, 2015 14:06
-
-
Save srikat/3f2b436dbec83c627a2d to your computer and use it in GitHub Desktop.
A slightly improved 'Add Nav Extras' code for adding Search in Navigation. http://sridharkatakam.com/slightly-improved-add-nav-extras-code-adding-search-navigation/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Do NOT include the opening php tag | |
add_filter( 'wp_nav_menu_items', 'theme_menu_extras', 10, 2 ); | |
/** | |
* Filter menu items, appending a search form. | |
* | |
* @param string $menu HTML string of list items. | |
* @param stdClass $args Menu arguments. | |
* | |
* @return string Amended HTML string of list items. | |
*/ | |
function theme_menu_extras( $menu, $args ) { | |
//* Change 'primary' to 'secondary' to add search form to the secondary navigation menu | |
if ( 'primary' !== $args->theme_location ) | |
return $menu; | |
$menu .= '<li class="right search">' . get_search_form( false ) . '</li>'; | |
return $menu; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ob_start(); | |
get_search_form(); | |
$search = ob_get_clean(); | |
$menu .= '<li class="right search">' . $search . '</li>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$menu .= '<li class="right search">' . get_search_form( false ) . '</li>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment