Adding a within ‘s from wp_nav_menu()

Yes, items_wrap is used to to modify or replace the default <ul> wrapper. To wrap the individual links inside of that element, simply use link_before and link_after, like so: wp_nav_menu( array( ‘theme_location’ => ‘some-location’, ‘link_before’ => ‘<span>’, ‘link_after’ => ‘</span>’, ) );

Walker_Nav_Menu: put custom code between a particular

You need to make your own walker menu (i am guessing you already know that), and the best way i think is overriding the function that ends each menu item which is end_el : class logo_in_middle_Menu_Walker extends Walker_Nav_Menu { public $menu_location = ‘primary’; function __construct($menu_location_var) { // parent class doesnt have a constructor so no … Read more

How do I give class to the dropdown sub-menu in the wp_nav_menu?

You can use Walker_Nav_Menu (WordPress Default class). Here is an example – In header.php file – <nav id=”header-menu”> <?php wp_nav_menu( array( ‘theme_location’ => ‘primary’, ‘walker’ => new Child_Wrap() ) ); ?> </nav> In my functions.php file – class Child_Wrap extends Walker_Nav_Menu { function start_lvl(&$output, $depth = 0, $args = array()) { $indent = str_repeat(“\t”, $depth); … Read more

wp_nav_menu() customized

In my basis theme I use a walker for a simplified output: <?php # -*- coding: utf-8 -*- /** * Create a nav menu with very basic markup. * */ class T5_Nav_Menu_Walker_Simple extends Walker_Nav_Menu { /** * Start the element output. * * @param string $output Passed by reference. Used to append additional content. * … Read more

How to add current, parent, and ancestor menu item IDs to body_class()?

From my comment earlier: Use the body_class() function in your header.php file or wherever your body tag is, e.g. <body <?php body_class(); ?>>. This will give you an output with a bunch of classes on the body that you can then use in your CSS. For example, <body class=”page page-id-114 page-parent page-template-default logged-in admin-bar”>. You … Read more

Adding attributes to link in wp_nav_menu using custom Walker function

You want to modify the start_el method as you did the start_lvl one. At its most basic it would mean altering this line: $item_output .= ‘<a’. $attributes .’>’; To look like this one: $item_output .= ‘<a class=”dropdown-toggle” data-toggle=”dropdown”‘. $attributes .’>’; It looks like you will need more complicated logic to avoid inserting that string in … Read more

replace current_page_item class in menu

Add this line at top of your display element function: add_filter(‘nav_menu_css_class’, ‘add_active_class_to_nav_menu’); Add this line at bottom of your display element function: remove_filter(‘nav_menu_css_class’, ‘add_active_class_to_nav_menu’); Add this function somewhere in your themes functions.php: function add_active_class_to_nav_menu($classes) { if (in_array(‘current-menu-item’, $classes, true) || in_array(‘current_page_item’, $classes, true)) { $classes = array_diff($classes, array(‘current-menu-item’, ‘current_page_item’, ‘active’)); $classes[] = ‘active’; } return … Read more