Add login link Automatically to Twenty Ten Menu

If you are using WordPress 3.0 menu system, you can easily add a login/logout link to the navigation menu by adding a small bit of code to your functions.php file. This can be used in a child theme, or any WordPress theme that supports 3.0 menus. You must be using the menu system, it won’t work if you just add menu links by creating pages.

<?php
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
 
        ob_start();
        wp_loginout('index.php');
        $loginoutlink = ob_get_contents();
        ob_end_clean();
 
        $items .= '<div class="menulogin">'. $loginoutlink .'</div>';
 
    return $items;
}

Login link in Twenty ten menu
You can leave it where it is which will look like another menu, or push it to the right like I’ve done by using

.menulogin{float: right; margin-right: 10px;}
.menulogin a:hover {background-color: #333;color:#fff;}

Code mostly from Vanweerd.com Enhancing your WordPress 3.0 menu.


Leave a Reply

Please use the forums for questions that do not relate to this post.
Wrap all code in [code] Your Code Here [/code] tags.

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>