Show or Hide Menu item for specific page or users

/*Show/Hide Menu item for specific page or users */
and also you can manage menu order by ietm


add_filter( 'wp_nav_menu_objects', 'custom_menu_item', 10, 2 );
function custom_menu_item ( $items, $args ) {

$new_links = array();
$className[] = array();
$className[] = 'menu-item';
if(is_user_logged_in())
{
// only if user is logged-in, do sub-menu link
$item = array(
'title'            => 'Training room',
'ID'               => 'menu-item-74773', // Add page id
'db_id'            => 'custom',
'url'              => get_permalink(74773), //Add Page ID
'classes'          => $className
);
}
$new_links[] = (object) $item;  // Add the new menu item to our array
unset( $item ); // in case we add more items below

$index = count( $items );  // integer, the order number.

array_splice( $items, 12, 0, $new_links ); // Set order of your menu item
return $items;
}

Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: