[Plugin: T5 Nav Menu] Add link in a submenu.
-
Hello,
I made some modifications on Thomas Scholz’s plugin to display a link to the buddypress profile page. That’s it :<?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 )
{
include_once( ABSPATH . ‘wp-admin/includes/plugin.php’ );
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() )
{
global $current_user;
$link->url = get_bloginfo(‘url’) . ‘/membres/’. $current_user->user_login . ‘/profile/’;
$link->title = __( ‘Espace Membre’ );
}
else
{
$link->url = get_bloginfo(‘url’) . ‘/login/’;
$link->title = __( ‘Se Connecter’ );
}$sorted_menu_items[] = $link;
return $sorted_menu_items;
}It works but I’m wondering how could I add the link in a submenu rather than the first level menu. Is it with the “menu_item_parent”, if it is, how should I do it ?
Thanks in advance.
- The topic ‘[Plugin: T5 Nav Menu] Add link in a submenu.’ is closed to new replies.