Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are overwriting the incorrect method. You need the <code>start_el</code> instead. Here is the code for it:</p> <pre><code>class add_span_walker extends Walker_Nav_Menu { function start_el( &amp;$output, $item, $depth = 0, $args = array(), $id = 0 ) { global $wp_query; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $class_names = ''; $classes = empty( $item-&gt;classes ) ? array() : (array) $item-&gt;classes; $classes[] = 'menu-item-' . $item-&gt;ID; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item-&gt;ID, $item, $args ); $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; $output .= $indent . '&lt;li' . $id . $class_names .'&gt;'; $attributes = ! empty( $item-&gt;attr_title ) ? ' title="' . esc_attr( $item-&gt;attr_title ) .'"' : ''; $attributes .= ! empty( $item-&gt;target ) ? ' target="' . esc_attr( $item-&gt;target ) .'"' : ''; $attributes .= ! empty( $item-&gt;xfn ) ? ' rel="' . esc_attr( $item-&gt;xfn ) .'"' : ''; $attributes .= ! empty( $item-&gt;url ) ? ' href="' . esc_attr( $item-&gt;url ) .'"' : ''; $item_output = $args-&gt;before; $item_output .= '&lt;a'. $attributes .'&gt;'; $item_output .= $args-&gt;link_before . apply_filters( 'the_title', $item-&gt;title, $item-&gt;ID ) . $args-&gt;link_after; if ( 'primary' == $args-&gt;theme_location ) { $submenus = 0 == $depth || 1 == $depth ? get_posts( array( 'post_type' =&gt; 'nav_menu_item', 'numberposts' =&gt; 1, 'meta_query' =&gt; array( array( 'key' =&gt; '_menu_item_menu_item_parent', 'value' =&gt; $item-&gt;ID, 'fields' =&gt; 'ids' ) ) ) ) : false; $item_output .= ! empty( $submenus ) ? ( 0 == $depth ? '&lt;span class="arrow"&gt;&lt;/span&gt;' : '&lt;span class="sub-arrow"&gt;&lt;/span&gt;' ) : ''; } $item_output .= '&lt;/a&gt;'; $item_output .= $args-&gt;after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } } </code></pre> <p>This code will add a <code>&lt;span class="sub-arrow"&gt;&lt;/span&gt;</code> to top-level menu items from the menu selected for the <code>primary</code> theme location in case that this menu item has any child items.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload