Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

T5 Nav Menu Log-in Link Adds a log-in or log-out link to the first level of the first WordPress nav menu

View t5-nav-menu-log-in.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
<?php
/**
* Plugin Name: T5 Nav Menu Log-in Link
* Description: Adds a log-in or log-out link to the first level of the first nav menu
* Plugin URI: http://wordpress.stackexchange.com/q/77614
* Version: 2012.12.30
* Author: Thomas Scholz
* Author URI: http://toscho.de
* Licence: MIT
* License URI: http://opensource.org/licenses/MIT
*/
add_filter( 'wp_nav_menu_objects', 't5_menu_log_link', 100, 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. If $args->add_loginout is FALSE,
* the function does nothing.
* @return array Nav menu items
*/
function t5_menu_log_link( $sorted_menu_items, $args )
{
static $done = FALSE;
if ( ! isset ( $args->add_loginout ) && $done )
return $sorted_menu_items;
if ( isset ( $args->add_loginout ) && ! $args->add_loginout )
return $sorted_menu_items;
$done = TRUE;
$here = esc_url( home_url( $_SERVER['REQUEST_URI'] ) );
$link = new stdClass;
$link->menu_item_parent = 0;
$link->ID = '';
$link->db_id = '';
if ( is_user_logged_in() )
{
$link->url = wp_logout_url( $here );
$link->title = __( 'Log Out' );
}
else
{
$link->url = wp_login_url( $here );
$link->title = __( 'Log In' );
}
$sorted_menu_items[] = $link;
return $sorted_menu_items;
}

Not working for me.
Fatal error: Cannot redeclare t6_menu_log_link() in /customers/d/b/b/musikfest.dk/httpd.www/kursus/wp-content/plugins/o_add_menu_item/o_add_men_item.php on line 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.