Tuesday, 15 March 2011

php - How to filter the sub-menu classname in WordPress navigation menus? -



php - How to filter the sub-menu classname in WordPress navigation menus? -

in wordpress when using navigation menus, second-level menus given class sub-menu. example:

<ul> <li> <a title="page 1" href="/page-1/">page 1</a> <ul class="sub-menu"> <li> <a title="sub page 1" href="/sub-page-1/">sub page 1</a> </li> <li> <a title="sub page 2" href="/sub-page-2/">sub page 2</a> </li> </ul> </li> </ul>

i'm using bootstrap 3 need classname dropdown-menu. effort far has been re-create of dropdown-menu classes bootstrap.css theme's style.css , alter names sub-menu. isn't great approach because when next upgrade bootstrap, i'll need check hasn't changed.

my next thought filter classname. wordpress provide filter allow me alter classname?

update

i found walker solution here lets me alter sub-menu class.

class my_walker_nav_menu extends walker_nav_menu { function start_lvl(&$output, $depth) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<ul class=\"my-sub-menu\">\n"; } }

i'm pasting straight theme's functions.php. allows me alter classname problem next php debug notice:

strict standards: declaration of my_walker_nav_menu::start_lvl() should compatible walker_nav_menu::start_lvl(&$output, $depth = 0, $args = array) in /wp-content/themes/my-theme/functions.php on line 224

should pasting walker straight theme's functions.php? going wrong?

why don't opposite? instead of editing css, edit theme file. alter ul's class.

<ul class="dropdown-menu"> ... </ul>

if need maintain "sub-menu" class in ul reason, can utilize both in same element. add together "bootstrap.css" class ul.

<ul class="sub-menu dropdown-menu"> ... </ul>

php css wordpress twitter-bootstrap

No comments:

Post a Comment