Right now I have it so when you are logged in, the menu in the header displays a welcome message with the username of the logged in person. And if nobody is logged in, it displays “login”. I have the following code in functions.php

add_filter( 'wp_nav_menu_items', 'my_custom_menu_item');
function my_custom_menu_item($items)
{
    if(is_user_logged_in())
    {
        $user=wp_get_current_user();
        $name=$user->display_name; // or user_login , user_firstname, 
user_lastname
        $items .= '<li><a href="">Welcome '.$name.'</a></li>';
    }
    else
    {
        $items .= '<li><a href="">Login</a></li>';
     }
    return $items;
     }

How would I go about having another link in the menu that says “log out” next to the welcome message when logged in, and a “register” next to the “login” when not logged in?

Also, right now the welcome message and login elements are appearing in both the upper left corner menu and the main navigation menu. However, I only want it to appear in the upper left. How would I go about fixing this?

Link to the site I’m working on if it helps: digitalenclave.net

Read more here: How do I add more than one element to a menu in WordPress in PHP


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: