When a user is not logged in I am trying to show
Support || Log In
When they are logged out it should say
Support || Log Out
Here is the code I tried to use to get this to work
<div class="fr">
<ul class="rss">
<li><a href="http:/jfdfjdf.com/wp-login.php">Support</a></li>
<li><?php if (is_user_logged_in() ) { echo " <a href=" . wp_logout_url() . " title=\"Logout\">Logout</a>";}?></li>
<li><?php else if (!is_user_logged_in() ) { echo " <a href="fdjdjfd.com" title=\"Logout\">Member Login</a>";}?></li>
</ul>
</div>
But it is not working can anybody help me out?
Use this code:
Your mistake is that you should not insert anything between closing
}
andelse
keyword. Also, in templates, oldschoolif
,while
,foreach
form should be used - see above.Another way to display content for users with a shortcode. Post this into functions.php
Have you tried changing
?php else if (!is_user_logged_in() )
to just?php if (!is_user_logged_in() )
?Add this to functions.php in your theme or create a plugin. Change 'menu' to the menu location eg. 'primary-menu' in your theme. Change 'logged-in' to the name of the logged in menu and logged out respectively.
referenced from: WPBeginner
Apart from coding you can always use a plugin called Nav Menu Roles
Not sure about the result of your function, but to start you were not escaping properly. Secondly, why not just use one
li
to house the correct link as follows: