How does a minimal menu walker look like?

You could create a very simple walker, like this one. To detect the current item, inspect $item->current. It is TRUE for the current item only.

I wouldn’t add a class, but deactivate the useless link completely, because it doesn’t have to be clickable anyway.

Example:

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

        foreach ( $elements as $item )
        {
            if ( $item->current )
                $list[] = "<b title="You are here">$item->title</b>";
            else
                $list[] = "<a href="https://wordpress.stackexchange.com/questions/112442/$item->url">$item->title</a>";
        }

        return join( "\n", $list );
    }
}

In your theme use the walker like this:

wp_nav_menu(
    array (
        'theme_location'  => 'your_theme_location',
        'walker'          => new One_Line_Walker,
        'container'       => '',
        'items_wrap' => '<p>%3$s</p>',
        'depth'           => 1
    )
);

See my post about items_wrap for an explanation of <p>%3$s</p>.

Leave a Comment