How can I make wp_nav_menu() support tags?
You can wrap menu link texts in html tags, in example Menu <span>Item</span>. Now you can create line break with CSS. .nav span { display: block; }
You can wrap menu link texts in html tags, in example Menu <span>Item</span>. Now you can create line break with CSS. .nav span { display: block; }
You could use the nav_menu_item_id filter like this: add_filter( ‘nav_menu_item_id’, function( $menu_id, $item, $args, $depth ) { if( ‘menu-item-27’ === $menu_id ) $menu_id = ‘nava’; return $menu_id; }, 10, 4 ); but I this is “unstable” regarding the menu ID, if you delete and re-insert menu items. You might also want to target a specific … Read more
Go with a custom Walker class Your_Walker_Nav_Menu extends Walker_Nav_Menu { var $container_class; public function __construct($container_class) { $this->container_class = $container_class; } function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { global $wp_query; $indent = ( $depth > 0 ? str_repeat( “\t”, $depth ) : ” ); // code indent // … Read more
No need for a custom walker – it’s controlled with the depth parameter. At the moment, you’re only showing 2 levels of menus – but you need to set this to 3! This, however, will only control what is being output. As for the user clicking, hovering or otherwise to actually see the menu, you’ll … Read more
I just posted an answer to this here: How to create this custom menu walker? Basically, you want your start_el and end_el to looks something like this: function start_el(&$output, $item, $depth=0, $args=array()) { $output .= ‘<a href=”#”><span>’ . esc_attr($item->label); } function end_el(&$output, $item, $depth=0, $args=array()) { $output .= ‘</span></a>’; }
Those are arguments in string form, which is just key=value, with an ampersand & separating each argument. In the form of an array, they would be: array( ‘title_li’ => ”, ‘sort_column’ => ‘menu_order’, );
Do you have error logging on? If you’re running the latest version of WP, this should be throwing an error because start_el and end_el are public functions. Also, if you’re using a custom walker, you should only use the walker and not your additional theme_function. class wpseWalker extends Walker_Nav_Menu { public function start_el(&$output, $item, $depth … Read more
Here is your walker class class Description_Walker extends Walker_Nav_Menu { function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat(“\t”, $depth); $output .= “\n$indent<nav class=”dropdown-list w-dropdown-list”>\n”; } function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { $classes = empty($item->classes) ? array () : (array) $item->classes; … Read more
You should be able to use nav_menu_link_attributes to add attributes to links output by wp_nav_menu that have child/submenu links. wp_nav_menu conditionally assigns classes to links it outputs. You need to target links with the class .menu-item-has-children You can add the attributes you want with the following filter/function: add_filter( ‘nav_menu_link_attributes’, ‘wpse270596_add_navlink_atts’, 10, 3 ); function wpse270596_add_navlink_atts( … Read more
The get_avatar() function has many arguments, the last one is the interesting one, because you can pass additional classes, also described in the codex. So instead of get_avatar( $comment, $args[‘avatar_size’] ); you could use get_avatar( $comment, $args[‘avatar_size’], ”, ”, array(‘class’ => ‘myclass’) );