I’m using wp_nav_menu and am trying to create custom output for the sub-level drop downs. I came across the “items_wrap” argument but there’s really not much information as to what it is, how it works, and what kind of things can be done with it.
What exactly is “%1$s” and “%2$s“? (Can anyone explain it in layman’s terms?)
The parameter
'items_wrap'
forwp_nav_menu()
defaults to:This a a template that is parsed with
sprintf()
:The numbered placeholders â
%1$s
,%2$s
,%3$s
â refer to the arguments after the first argument insprintf()
. The percent sign marks a placeholder, the number the position and the types
means it should be treated as a string.Do not change the type unless you really know what you do. 🙂
$wrap_id
is the parameter'menu_id'
if you have it set, else it is'menu-' . $menu->slug
.$wrap_class
is the parameter'menu_class'
if you have it set, else it is empty.$items
is a string of the inner content of the menu.Letâs say you donât need a
class
. Just omit the second string:If you donât need the
class
and theid
, and you want another container (because you used a custom walker):The main point is: You have to use the numbers for the replacements given in
wp_nav_menu()
.%3$s
is always the list of items.from what i gather it grabs an output and give the li a id and class with the menus name. So when you want to style a particular menu you grab its id and or class if you want to style it. the 1 and 2 is just a different output.