Skip to content

Instantly share code, notes, and snippets.

@frankschrijvers
Last active February 24, 2016 01:01
Show Gist options
  • Save frankschrijvers/3a1fd0ae71e05adb445f to your computer and use it in GitHub Desktop.
Save frankschrijvers/3a1fd0ae71e05adb445f to your computer and use it in GitHub Desktop.
Add WooCommerce Search Box to navigation Genesis
add_filter( 'wp_nav_menu_items', 'wpstudio_add_woo_search', 10, 2 );
/**
* Add WooCommerce cart to primary navigation Genesis
* @author Frank Schrijvers
* @link https://www.wpstud.io/add-woocommerce-cart-to-genesis-navigation/
*/
function wpstudio_add_woo_search( $menu, $args ) {
//* Change 'primary' to 'secondary' to add the woocommerce search to the secondary navigation menu
if ( 'primary' !== $args->theme_location )
return $menu;
$form = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '">
<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' . __( 'Search for products', 'woocommerce' ) . '" />
<input type="submit" id="searchsubmit" value="'. esc_attr__( 'Search', 'woocommerce' ) .'" />
<input type="hidden" name="post_type" value="product" />
</form>';
$menu .= '<li class="searchbox">' . $form . '</li>';
return $menu;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment