Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to display a simple menu like this:

<nav class="main">
<a href="/" class="home">
    <span class="logo"></span>
    <span class="company-name">My Company</span> 
    <span class="page-name">Home</span>
</a>
<a href="one-page">One page</a>
<a href="two-page" class="selected-current">Two page</a>
<a href="three-page">Three page</a>
<a href="about">About</a>
<div class="account">
    <a href="login" class="login">Login</a>
</div>

For this I proceed in this way:

/theme/function.php

<?php
// Adding Log in/out links to a Specific WordPress Menu
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
    if (is_user_logged_in() && $args->theme_location == 'primary') {
        $items .= '<div class="account"><a href="'. wp_logout_url() .'" class="login">Logout</a></div>';
    }
    elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
        $items .= '<div class="account"><a href="'. site_url('wp-login.php') .'" class="login">Login</a></div>';
    }
    return $items;
}

/theme/header.php

<nav class="main"><?php
$menuParameters = array(
  'theme_location' => 'primary',
  'fallback_cb'     => 'starkers_menu',
  'container'       => false,
  'echo'            => false,
  'items_wrap'      => '%3$s',
  'depth'           => 0,
);
echo strip_tags(wp_nav_menu( $menuParameters ), '<a><div>' );
?></nav>

I can not manage the class pages for current and the tags (span) for the first url (home).

Thank you in advance for your help.

cordially

share|improve this question
Can you be more precise about what the problem is? Also, what is the purpose of strip_tags() on the menu? – helgatheviking Jan 25 at 0:21

1 Answer

thank you for your answer.

I want to display my menu exactly like this:

<nav class="main">
    <a href="/" class="home">
        <span class="logo"></span>
        <span class="company-name">My Company</span> 
        <span class="page-name">Home</span>
    </a>
    <a href="one-page">One page</a>
    <a href="two-page" class="selected-current">Two page</a>
    <a href="three-page">Three page</a>
    <a href="about">About</a>
    <div class="account">
        <a href="login" class="login">Login</a>
    </div>
</nav>

(strip_tags() allows me to remove the tags (li) by default.

I can not customize the first part of my menu as follows:

<a href="/" class="home">
    <span class="logo"></span>
    <span class="company-name">My Company</span> 
    <span class="page-name">Home</span>
</a>

and add a style (class = "current-selected") to the menu item corresponding to the current page.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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