Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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/

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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? –  toscho 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/fu‌​nctions.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. –  toscho 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

 
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.