Add items to a menu dynamically

You could achieve this with a custom walker function, on your menu. a very simple example:

class Walker_WPA82563_Submenu extends Walker_Nav_Menu {
    function end_el(&$output, $item, $depth=0, $args=array()) {
        if( 'Boats' == $item->title ){
            $output .= '<ul><li>Dynamic Subnav</li></ul>';
        }
        $output .= "</li>\n";  
    }
}

Then where you call the nav menu, create an instance of your custom walker with the walker argument.

wp_nav_menu(
    array(
        'theme_location' => 'primary',
        'walker' => new Walker_WPA82563_Submenu
    )
);

Leave a Comment