filters – Set Item Order with wp_nav_menu_{$menu->slug}_items

Question

you can always search & replace by string or regex the output html of the filtered $items.
anyway, if you’re targeting usual menu items, you can add $post objects and order items through the wp_nav_menu_objects filter, otherwise here’s the basic sample code:

function replace_itemcart_in_menu( $items, $args ) { 
    $url = home_url('my-item');
    $previtem = '<li id="menu-item-11" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-11"><a href="'.$carturl."https://wordpress.stackexchange.com/">My Item</a>'; 
    $newitem = '<li>New Item</li>'; 
    $items = str_replace($previtem, $previtem.$newitem, $items); 
    return $items; 
}

0
s_ha_dum 8 years 2013-05-24T16:51:19-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse