Walker_Nav_Menu doesn’t work in wp_page_menu_args filter

Old Q, but I’ll give my 2 cents. The walker class should inherit Walker_Page, not Walker_Nav_Menu as is usually the case with guides on the ‘net. The $item object is a Post Object, containing post_title and ID. To output the URL, you need to call get_permalink($item-ID). Regarding $item->url, it will be unset. Both theme_location and … Read more

Add within the output of

Use the arguments before and after: wp_nav_menu( array( ‘theme_location’ => ‘primary’, ‘menu_class’ => ‘nav-menu’, ‘before’ => ‘<span>’, ‘after’ => ‘</span>’ ) ); To see how these arguments are used, look at the method start_el() in Walker_Nav_Menu: $item_output = $args->before; // ‘before’ $item_output .= ‘<a’. $attributes .’>’; $item_output .= $args->link_before . apply_filters( ‘the_title’, $item->title, $item->ID ) … Read more

Custom walker nav – Add sequential number as class

Try it like this: class ik_walker extends Walker_Nav_Menu { function start_lvl(&$output, $depth) { $GLOBALS[‘ik_walker_counter’] = 0; $output .= ‘<nav class=”site-navigation” role=”navigation”>’. ‘<ul>’; } function end_lvl(&$output, $depth) { $output .= ‘</ul>’. ‘<button id=”menu” class=”menu-button” type=”button” role=”button” aria-label=”Menu Toggle”>’. ‘<span class=”icon-menu”></span>’. ‘</button>’. ‘</div>’; } function start_el(&$output, $item, $depth, $args) { global $wp_query; global $ik_walker_counter; $indent = ( … Read more

Use menu class in walker function

Joining all class names: Please try: $item_output .= sprintf( ‘<span class=”%s”></span>’, join( ‘ ‘, $item->classes ) ); instead of $item_output .= ‘<span class=”‘. $item->classes .'”></span>’; to join the array elements of $item->classes into a string. If you add for example aaa bbb ccc to an item’s class text field, it will show up like this: … Read more

Make parent page only link to first subpage

class Themeslug_Page_Navigation_Walker extends Walker_Nav_Menu { function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) { $id_field = $this->db_fields[‘id’]; if ( !empty( $children_elements[ $element->$id_field ] ) ) { $element->url = $children_elements[$element->$id_field][0]->url; } Walker_Nav_Menu::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); } } This did the trick.

Change an li class name in a wordpress custom menu walker

Troubleshooting Enabling the WP_DEBUG constant in wp-config.php exposed the following errors: – Function Signatures If Strict Standards is enabled, you’ll see an error detailing incompatible method signatures. Though not absolutely necessary, I like to eliminate as many errors as possible. To correct this, the new Walker_Nav_Menu class’s start_el() and start_lvl() methods’ declarations need to match … Read more

View h2 content tags of a page in sub menu

Basically, you add a custom walker to wp_nav_menu. Whenever an item begins, you can check for the content of the page underlaying the navigation item. When a content is available, read the content into a new DOMDocument-Object and filter out all titles. With the titles, create sub-links to the current link beeing made in the … Read more

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