How to Programically add to the new WordPress menus
You ca use the filters ‘wp_nav_menu_items’ and “wp_nav_menu_{$menu->slug}_items”. See ‘wp-includes/nav-menu-template.php’, line 222.
You ca use the filters ‘wp_nav_menu_items’ and “wp_nav_menu_{$menu->slug}_items”. See ‘wp-includes/nav-menu-template.php’, line 222.
Could you explain your context a little? I also think CSS is very fitting solutions to this. Partly because it makes sense for content/presentation balance, partly because custom menus are quite complex to figure out and I usually stay away form their internals. I use CSS with set of icons at my blog, so I … Read more
Goto Appearance -> Menus -> Create a new menu -> Add your link as custom link
In regard to this comment: I see – I had things nested incorrectly in my functions.php file – I found that the register_nav_menus() call should not be nested within the theme setup function (function hchw_setup()) To the contrary, inside a callback hooked into after_setup_theme is exactly the right place for calls to register_nav_menus(). Your problem … Read more
The data for Currently Active Menus is not included in the exports (by default). This is because there is no guarantee the importing site will have the same theme (or same named menus). If changing the menus was a big deal, you could export/import all the data straight out of the database. (This option is … Read more
Not sure this is the simplest means, but you could conditionally add the filter to just the location you want to modify via wp_nav_menu_args filter when wp_nav_menu is called, then immediately remove the filter so it isn’t applied to other menus. function wpa108544_nav_menu_args( $args ){ // check if it’s the location we want the filter … Read more
After doing some research this answer became a bit longer than expected, but this is the essence: TL;DR: Menu placement and Widget placement/order is saved on a Theme basis and can therefore be restored when switching Themes. This does not include the individual settings of Menus and Widgets, so if you change them these changes … Read more
Per comments, it’s called with call_user_func_array, so the 1st 2 elements get assigned to the declared arguments $elements and $max_depth, leaving the third element ($r which is the original $args) to be assigned via array_slice to $args. Eg function wpse172812( $elements, $max_depth ) { $args = array_slice(func_get_args(), 2); error_log(“elements=$elements, max_depth=$max_depth, args=” . print_r( $args, true … Read more
Yes, items_wrap is used to to modify or replace the default <ul> wrapper. To wrap the individual links inside of that element, simply use link_before and link_after, like so: wp_nav_menu( array( ‘theme_location’ => ‘some-location’, ‘link_before’ => ‘<span>’, ‘link_after’ => ‘</span>’, ) );
You need to make your own walker menu (i am guessing you already know that), and the best way i think is overriding the function that ends each menu item which is end_el : class logo_in_middle_Menu_Walker extends Walker_Nav_Menu { public $menu_location = ‘primary’; function __construct($menu_location_var) { // parent class doesnt have a constructor so no … Read more