Create a gist now

Instantly share code, notes, and snippets.

T5 Nav Menu Log-in Link Adds a log-in or log-out link to the first level of the first WordPress nav menu
<?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;
}
@boje

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