Add Commas Between Menu Items?

Use a very simple custom walker …

class WPSE_82726_Comma_Walker extends Walker
{
    public function walk( $elements, $max_depth )
    {
        $list = array ();

        foreach ( $elements as $item )
            $list[] = "<a href="https://wordpress.stackexchange.com/questions/82726/$item->url">$item->title</a>";

        return join( ', ', $list );
    }
}

… and call your menu like this:

wp_nav_menu(
    array (
        'theme_location' => 'your_registered_theme_location',
        'walker'         => new WPSE_82726_Comma_Walker,
        'items_wrap'     => '<p class="menu">%3$s</p>'
    )
);

Fast and efficient. 🙂

Leave a Comment