0

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/

stealthyninja
  • 1,130
  • 1
  • 15
  • 21
boje
  • 203
  • 1
  • 2
  • 7

1 Answers1

1

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.

fuxia
  • 107,219
  • 39
  • 255
  • 462