How to reference argument data for wp_nav_menu() from functions.php

a function like this: function get_nav_args($overrides = array()) { $defaults = array( ‘theme_location’ => ‘main-menu’, ‘menu_class’ => ‘list-inline’, ‘add_li_class’ => ‘list-inline-item’, ); return shortcode_atts($defaults, apply_filters(‘some_custom_identifier_nav_menu_args’, $overrides, $defaults) ); } would be callable like wp_nav_menu(get_nav_args()) using shortcode atts and allowing an overrides array to be passed in would allow you to change the values if necessary … Read more

WordPress Menu adds an unwanted slash before anchor

You can likely change that by removing the slash from the end of the permalink structure on wp-admin/options-permalink.php & you should be good to go. But as Krzysiek Dróżdż has said: It shouldn’t make a difference in the execution of javaScript & trailing slashes are a best-practaice.

Hide menu item when users are logged in/out

I should suggest a custom walker to, not that hard at all. starting with: https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/ in the foreach loop you are able to check based on title. in this part you will use: https://developer.wordpress.org/reference/functions/is_user_logged_in/ foreach($nav_items as $item): if($item->title == ‘Register’): if(is_user_logged_in()): //Do your thing when logged in else: //Do your thing when not logged in … Read more

WordPress custom Nav Walker

You don’t need to write a custom walker to achieve this. You can modify the output of the wp_nav_menu() function and hook into the appropriate default nav menu filter to modify the output of the individual menu items. E.g. (assuming your theme menu location is called primary) Put this in your functions.php file /** * … Read more

How to add custom li item to wordpress menu

Default usage of add_filter looks like this: add_filter( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 ) As you can see, the default priority is 10 and by default only one param is passed. In your code you need your filter to get 2 params, because wp_nav_menu_items takes 2 params ($items … Read more