Skip to content

Instantly share code, notes, and snippets.

@mrkkr
Created April 26, 2018 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkkr/1bd43e11dde44ffd6d97da4c0d4ed65d to your computer and use it in GitHub Desktop.
Save mrkkr/1bd43e11dde44ffd6d97da4c0d4ed65d to your computer and use it in GitHub Desktop.
Add custom items (wraps) to menu item Wordpress #php
<?php
function my_nav_wrap() {
// default value of 'items_wrap' is <ul id="%1$s" class="%2$s">%3$s</ul>'
ob_start();
the_widget( 'WC_Widget_Product_Search' ); //in this case I need WC widget
$widget = ob_get_clean();
// open the <ul>, set 'menu_class' and 'menu_id' values
$wrap = '<ul id="%1$s" class="%2$s">';
// the widget
$wrap .= $widget;
// get nav items as configured in /wp-admin/
$wrap .= '%3$s';
// close the <ul>
$wrap .= '</ul>';
// return the result
return $wrap;
}
<?php
wp_nav_menu(
array(
'theme_location' => 'primary',
'items_wrap' => my_nav_wrap(),
'container_class' => 'collapse navbar-collapse',
'container_id' => 'mobileCategoryMenu',
'menu_class' => 'navbar-nav mobile-cat-menu',
'menu_id' => 'mobile-cat-menu',
'depth' => 3,
'walker' => new wp_bootstrap_navwalker(),
)
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment