How to modify navigation menu of the “My Account” page in WooCommerce

For that, you do not need to modify the woocommerce/templates/myaccount/navigation.php. The best way to customize the “My Account” navigation menu items is to use: woocommerce_account_menu_items filter hook to add new items to the menu. array_slice() to reorder them the way you want. This way, by using woocommerce_account_menu_items filter hook, you integrate perfectly your own items … Read more

How to add custom post type archive page links to nav menu?

This is one method that I think should work (though it’s not tested). //Hook on to the filter for the (custom) main menu // ‘wp_list_pages’ filter is a fallback, when a custom menu isn’t being used add_filter( ‘wp_list_pages’, ‘new_nav_menu_items’ ); add_filter( ‘wp_nav_menu_items’, ‘new_nav_menu_items’ ); //Can also hook into a specific menu… //add_filter( ‘wp_nav_menu_{$menu->slug}_items’, ‘new_nav_menu_items’ ); … Read more

Filter wp_nav_menu()

I think I got the answer: function my_nav_menu( $args = array() ) { $echo = isset( $args[‘echo’] ) ? (bool)( $args[‘echo’] ) : true; $args[‘echo’] = false; add_filter( ‘wp_nav_menu_objects’ , ‘my_filter_nav_menu’ , 100 , 2 ); $menu = wp_nav_menu( $args ); remove_filter( ‘wp_nav_menu_objects’ , ‘my_filter_nav_menu’ , 100, 2 ); if( $echo ) echo $menu; else … Read more

Add custom menu item using wp_nav_menu_items filter

I’ve created these two functions you may use to add custom items to a given menu item present in your menu (page, post, link…). In your case, you can add these function to your functions.php and call them like this: $menu_name=”Your Menu Name”; $name_of_menu_item_to_append_to = ‘My Account’; $id_of_menu_item_to_append_to = get_wp_object_id( $name_of_menu_item_to_append_to, ‘nav_menu_item’ ); $new_submenu_item = … Read more

Add Javascript to WordPress Menu

Good that it works. If it’s for a client or if you just want a cleaner code, you can do it as @Tom J Nowell suggested. Add a custom menu item, link it to nowhere or anywhere. Find out the menu item ID (every item has one), and then target that ID with jQuery. $(“#menu-item-num”).on(“click”, … Read more

How Does The Walker Class Work?

I searched and read about the walker class. I ran tests, I played around with the code and I finally understood. I hope this can be helpful to others too. You’ll need to implement the walker class for this. Here is a simple example. $defaults = array( ‘theme_location’ => ‘primary’, ‘container’ => ‘ul’, ‘menu_class’ => … Read more

How to count nav menu items?

Call wp_get_nav_menu_object to get a menu object, which will give you the count of items for that menu. Example: // Get menu object $my_menu = wp_get_nav_menu_object( ‘your-menu-name-or-slug’ ); // Echo count of items in menu echo $my_menu->count; Hope that helps.

How to Add to Each Menu Link with link text to data-attr?

Solution 1: Using customize walker I got some idea from add span class inside wp_nav_menu link anchor tag and made some changes for your requirements. 1. Add this code below to your functions.php first. class Nav_Walker_Nav_Menu extends Walker_Nav_Menu{ function start_el(&$output, $item, $depth, $args){ global $wp_query; $indent = ( $depth ) ? str_repeat( “\t”, $depth ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)