How can I remove data-target=”#” from bootstrap dropdown menu?

Your options are the following: Extend the walker and change the output (override start_el function) Here is an example of the Walker, assuming you are using this bootstrap walker. Usage: ‘walker’ => new se150102_bootstrap_walker() Walker: class se150102_bootstrap_walker extends wp_bootstrap_navwalker { /** * This walker is identical to the parent start_el() function, except * it does … Read more

Counting top level items in a custom menu walker

Calculation you talking about going here: if( !isset( $this->break_point ) ) $this->break_point = ceil( $this->current_menu->count / 2 ) + 1; You can’t get top-level items count this way. Instead you should count it yourself. You can do this using wp_get_nav_menu_items(). Every top-level item should have menu_item_parent set to ‘0’. You should create additional variable where … Read more

Adding Custom “Current Menu Item” class to navigation?

You declared the same function name, that’s the cause of the “declared error”. Just change the class function (including in the filter hook). Or you can just extend your function code. I also would rewrite the if structure to have a more easy readibility: add_filter( ‘nav_menu_css_class’, ‘add_custom_class’, 10, 2 ); function add_custom_class( $classes = array(), … Read more

Custom menu output

You can try the following to modify the links of the menu items that are pages: add_filter( ‘nav_menu_link_attributes’, function( $atts, $item, $args, $depth ) { if( isset( $item->object ) && ‘page’ === $item->object && isset( $args->theme_location ) && ‘primary’ === $args->theme_location ) $atts[‘href’] = home_url( sprintf( ‘/#/page/%d’, $item->object_id ) ); return $atts; }, 10, 4 … Read more

$variable (counter) inside wp nav menu

Counter – Inside Menu Links You can e.g. use the nav_menu_item_titleCodex filter to adjust the menu titles: add_filter( ‘nav_menu_item_title’, function( $title, $item, $args, $depth ) { static $instance = 0; // Append an increasing counter to the menu title for menu items // within a given menu location and menu class if( ‘my-custom-location’ === $args->theme_location … Read more

Adding post excerpt into navigation menu

wp_nav_menu() calls walk_nav_menu_tree() which calls the Walker_Nav_Menu class. There are a couple of filters you can hook into in those functions but I would take a look at the nav_menu_item_title filter in the Walker_Nav_Menu class. Here is the source: /** * Filter a menu item’s title. * * @since 4.4.0 * * @param string $title … Read more

How to add a tag to wp_nav_menu in a child theme

The wp_nav_menu() function has a ton ( or bunch ) of parameters which makes customization fairly easy. I believe the one you’re specifically looking for is after which will add a passed string into the list after the link. An example would look like this: wp_nav_menu( array( ‘menu’ => ‘Main Menu’, ‘container’ => ‘nav’, ‘theme_location’=> … Read more