How do I hide an item from a menu to logged out users (without a plugin) in WordPress?

How do I hide an item from a menu to logged out users (without a plugin) in WordPress?

Hi sknetking here you can do it by this code snippet -


add_filter( 'wp_nav_menu_items', 'add_extra_item_to_nav_menu', 10, 2 ); 
function add_extra_item_to_nav_menu( $items, $args ) { 
    if (is_user_logged_in()) { 
        $items .= '<li><a href="#">My Account</a></li>'; 
    } 
    elseif (!is_user_logged_in()) { 
        $items .= '<i><a href="#">Sign in  /  Register</a></li>'; 
    } 
    return $items; 
} 

just copy this code and past in your active theme functions.php file .

Post a Comment

0 Comments