Hi OP..
I’m trying to do the similar thing..I want the website to display “login register” when the user did not login and show logout when the user is logged in..I know I can add additional item to the menu, but it would not change to “log out” after user log in. I have been struggling to try to find a good way to do it…
When loggedin you probably have a body class “logged-in”, (your theme may vary?), so customise your menu entries to add a class to each of them, say “show-loggedin” and “show-loggedout”, then add css like this:
.show-loggedin { display: none;}
.logged-in .show-loggedin { display: block;}
.show-loggedout { display: block;}
.logged-in .show-loggedout { display: none;}
Each menu item in the $menu array actually has 7 elements, you have only provided the first three. 4th is usually an empty string. 5th is the element classes. 6th is the element ID. 7th is the icon reference, such as ‘dashicons-admin-plugins’ for the plug icon.
@sjjlin – wp_loginout() source code can be examined to see how the correct URL is decided upon. While you cannot use the function directly because it outputs HTML, you can use similar logic to determine the proper URL and menu label.
While your issue is similar to the OP’s, it’s not exactly the same. It rarely is no matter how it appears. Thus we ask members to always start their own topic instead of tagging onto other’s topics. Replies end up being confused when multiple issues are trying to be solved on the same thread.
Sucess! Thank you very much. The other elements were really missing.