How to display different links for logged in and l

2019-03-05 17:55发布

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?

标签: wordpress
8条回答
Explosion°爆炸
2楼-- · 2019-03-05 18:22

What about the following?

<div class="fr">
    <ul class="rss">
        <li><a href="http://example.com/wp-login.php">Support</a></li>
        <?php if (is_user_logged_in() ) { echo " <li><a href=" . wp_logout_url() . " title=\"Logout\">Logout</a></li>";}?>
        <?php else if (!is_user_logged_in() ) { echo " <li><a href="http://example.com/wp-login.php" title=\"Logout\">Member Login</a></li>";}?>
    </ul>
</div>

I moved the php if statements so you don't get empty li elements. You should still do the escaping that others have noticed.

查看更多
smile是对你的礼貌
3楼-- · 2019-03-05 18:34

Your code has a syntax error:

<li><?php else if (!is_user_logged_in() ) { echo " <a href="http://example.com/wp-login.php" title=\"Logout\">Member Login</a>";}?></li>

You should escape the double-quotes:

<li><?php else if (!is_user_logged_in() ) { echo " <a href=\"http://example.com/wp-login.php\" title=\"Logout\">Member Login</a>";}?></li>
查看更多
登录 后发表回答