2

I'm creating a template in HTML5. On navigatiom menu i need to implement something like this

<nav>
 <a href="url1">url1</a>
 <a href="url1">url2</a>
 <a href="url1">url3</a>
 <a href="url1">url4</a>
 ...
 <a href="urln">urln</a>
</nav>

If i use 'wp_nav_menu', it prints

<div><ul><li><a>

when i need just

<a>

There is a way to get that? Thanks!

2

Use a custom walker:

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

        foreach ( $elements as $item )
            $list[] = "<a href='$item->url'>$item->title</a>";

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

… and then call wp_nav_menu() like this:

wp_nav_menu(
    array (
        'theme_location' => 'your_registered_theme_location',
        'walker'         => new WPSE_33175_Simple_Walker,
        'items_wrap'     => '<nav>%3$s</nav>'
    )
);
| improve this answer | |
0

I'd suggest using the wp_nav_menu_items filter.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.