I can't find a way to add the log in link to the new theme of WordPress, Twenty Twelve. I did find a lot of answers on the older theme, where they suggest to add some code in the functions.php file. However, this do not work for me.

Does anyone have a solution for this? You can see my homepage here: http://musikfest.dk/kursus/


Filter wp_nav_menu_objects and add the link as item, similar to this answer.

add_filter( 'wp_nav_menu_objects', 't5_menu_log_link', 10, 2 );

 * Add a link to the nav menu.
 * @wp-hook wp_nav_menu_objects
 * @param  array  $sorted_menu_items Existing nav menu items
 * @param  object $args Nav menu arguments. 'add_loginout' must be TRUE
 * @return array  Nav menu items
function t5_menu_log_link( $sorted_menu_items, $args )
    $is_in                  = is_user_logged_in();

    $link                   = new stdClass;
    $link->title            = __( $is_in ? 'Log Out' : 'Log In' );
    $link->menu_item_parent = 0;
    $link->ID               = '';
    $link->db_id            = '';
    $link->url              = $is_in ? wp_logout_url() : wp_login_url();

    $sorted_menu_items[] = $link;

    return $sorted_menu_items;

Get it as plugin from GitHub.

  • I have added this as a plugin. link and add the code from here link as a function to function.php. I can't se any different? Do I need to do more? And if I add the code above the whole site fails. – boje Dec 29 '12 at 17:57
  • I am using this code on a site, and it works. What error message do you get? – fuxia Dec 29 '12 at 18:06
  • I get this error. I added the code to function like this link. I get the error when I click update. The error: Fatal error: Cannot redeclare t5_menu_log_link() (previously declared in /customers/d/b/b/musikfest.dk/httpd.www/kursus/wp-includes/nav-menu-template.php:505) in /customers/d/b/b/musikfest.dk/httpd.www/kursus/wp-content/themes/twentytwelve/functions.php on line 476 – boje Dec 29 '12 at 18:19
  • Do not define a function twice. Do not edit TwentyTwelve, create a child theme instead. – fuxia Dec 29 '12 at 18:20
  • I have copy the them and added new new theme again. I don't where I else where have define the function, so i renamed it to t5_menu_log_link in both the function and the add_filter. There are no errors but there are not link. – boje Dec 29 '12 at 18:32

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.