WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hey! I have added a wp_loginout() to my header using a snippet in my functions.php:

    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {

        $loginoutlink = ob_get_contents();

        $items .= '<li>'. $loginoutlink .'</li>';

    return $items;

The thing is that it shows the login link in every one of my three menues:

    function register_main_menus() {
         'primary-menu' => __( 'Primary Menu' ),
         'secondary-menu' => __( 'Secondary Menu' ),
         'footer-menu' => __( 'Footer Menu' ),

I would like to target the wp_nav_menu_items filter to only include the login link in the primary menu. Ideas? Thanks in advance

share|improve this question
up vote 5 down vote accepted

See this related question. I guess in your case you'd wrap your code in if( $args->theme_location == 'primary-menu' ).

share|improve this answer
I'm sorry I didn't see that one :) It works perfectly now! Thanks a bunch – Kasper Isager Mar 13 '11 at 12:59

Your Answer


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.