Highlight parent if item from submenu is active
Use the classes current-menu-ancestor current-menu-parent and menu-item-has-children
Use the classes current-menu-ancestor current-menu-parent and menu-item-has-children
Here you go. Since you already have the menu-id all you need is: $menu_item_defaults = array( ‘menu-item-db-id’ => $menu_item_db_id, ‘menu-item-object-id’ => 0, ‘menu-item-object’ => ”, ‘menu-item-parent-id’ => 0, ‘menu-item-position’ => 1, ‘menu-item-title’ => ‘Play Game’, ‘menu-item-url’ => ”,//not sure is a blank is ok here ‘menu-item-description’ => ”, ‘menu-item-attr-title’ => ”, ‘menu-item-target’ => ”, ‘menu-item-classes’ … Read more
It would be easier to add this on a menu link. The attributes for each link pass through the nav_menu_link_attributes filter. You should be able to use it to add a custom one, along the lines of (not tested): add_filter( ‘nav_menu_link_attributes’, function( $atts, $item ) { // check if $item is what you need $atts[‘data-slug’] … Read more
Given that you want to include a picture in the wp_nav_menu output, your best bet is to use the wp_nav_menu_items filter, as suggested in the comments. This will allow you to do a search and replace on the html. add_filter (‘wp_nav_menu_items’,’wpse229358_filter_menu’); function wpse229358_filter_menu ($items,$args) { $search=””; // html string of button $replace=””; // html string … Read more
This code checks if you’re on a category page, and if so it lists all the categories that are children of the current category. if (is_category()) { $this_category = get_category($cat); if (get_category_children($this_category->cat_ID) != “”) { wp_list_categories(‘orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of=”.$this_category->cat_ID); } }
There’s a specific filter for each nav item’s attributes: nav_menu_link_attributes. So, you can put in your functions.php file something like: function mysite_add_anchor( $atts, $item, $args ) { $atts[‘href’] .= ( !empty( $item->xfn ) ? ‘#’ . $item->xfn : ” ); return $atts; } add_filter( ‘nav_menu_link_attributes’, ‘mysite_add_anchor’, 10, 3 ); What this does, is check the … Read more
Finally, after several tests with jquery versions I found that the correct one was the jquery-1.8.0.min.js. Is the only one latest jquery version which is working with superfish.js. The jQuery versions after 1.8.0 seem to have problems working in combination with superfish.js (also tested the latest jQuery 3.1.1 with no result). So eventually I had … Read more
I was able to solve my own problem by using get_the_title with the post ID rather than using the_title. Then I decided to try using $subpost->post_title and that worked too. I figure this is better than get_the_title since it doesn’t have to “get” the data again, it just uses the data we’ve already gotten. I … Read more
This should work: add_filter( ‘wp_get_nav_menu_items’, ‘cpt_locations_filter’, 10, 3 ); function cpt_locations_filter( $items, $menu, $args ) { $child_items = array(); $menu_order = count($items); $parent_item_id = 0; foreach ( $items as $item ) { if ( in_array(‘locations-menu’, $item->classes) ){ //add this class to your menu item $parent_item_id = $item->ID; } } if($parent_item_id > 0){ foreach ( get_posts( … Read more
You code is working for me with (and without) some modifications on your code, to place in functions.php : add_filter( ‘nav_menu_css_class’, ‘menu_item_classes’, 10, 4 ); function menu_item_classes( $classes, $item, $args, $depth ) { unset($classes); $classes[] = ‘current-menu-ancestor’; return $classes; } If it’s still not working, verify that your are working on the right theme_location id … Read more