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

I am using twenty twelve with a child theme. I have a link in my primary nav menu where I have an link for “My Account” which has a sub menu with a “Login/Register” link that redirects to a modified wp-login.php. Is it possible for me to turn the “Login/Register” link into a “Logout” link when a user is logged in? If it is possible, would you know how I could accomplish this, or point me in the right direction?

Everything I've found online is adding a login/logout link to the primary menu. I would like to leave the menu intact since the "My Account" sub menu will have more links added to it.

I'm not sure if this is relevant but, I created the sub menu using Wordpress menus and created a custom link to redirect it to wp-login.php

Thank you

share|improve this question
Please show your code. – kaiser May 20 '13 at 0:50

Here's how I managed to set it up for one client. The code (which should go into the theme's functions.php) assumes there's an existing menu item titled 'Login'. Works fine but may not be the best way, so critique is welcome.

function wpse0520_modify_login_menu_item( $item ) {

        if( $item->title =='Login' ) {
                $item->url = wp_logout_url( get_permalink() );
                $item->title = 'Logout';
            } else {
                $item->url = site_url( 'login' );
        } elseif ( $item->title =='Logout' ) {
                $item->url = site_url( 'login' );
                $item->title = 'Login';
            } else {
                $item->url = wp_logout_url( get_permalink() );
    return $item;
add_filter( 'wp_setup_nav_menu_item', 'wpse0520_modify_login_menu_item' );
share|improve this answer
This is a perfect solution - just plug in an go. – Sri Aug 19 '13 at 19:37

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.