How to create and populate with few links a menu in child theme functions.php?

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

Customize existing menu item

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

Show subcategories on a parent category page

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); } }

Adding anchors in WordPress Menus

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

How can i automatically add CPT single pages as sub menu items

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

Add a custom class to nav li item

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