If user is logged in link

Hi Guys,

okay i have this bit of code but it doesnt seem to be working, my site is using wordpress

<?php
if ( is_user_logged_in() ) {
    echo '<li id="login" style="background:none;"><a href="<?php echo wp_logout_url(); ?>" title="Logout">Logout</a></li>';
} else {
    echo '<li id="login" style="background:none;"><a href="http://www.mysite.com/login">Login</a></li>';
};
?>

when i click the logout button it doesnt do anything except in my browser url it says http://www.mysite.com/&lt;?php echo wp_logout_url(); ?>

its echoing the php code instead of the url

what am i doing wrong :x

The problem is your’re embedding PHP tags in a string while you’re already in PHP mode (i.e. within a block of code in <?php and ?> tags), that won’t work. You need to concatenate the strings instead. That doesn’t sound very helpful, I know, so I’ll show you what I mean instead:


<?php
if ( is_user_logged_in() ) {
    echo '<li id="login" style="background:none;"><a href="' . wp_logout_url() . '" title="Logout">Logout</a></li>';
} else {
    echo '<li id="login" style="background:none;"><a href="http://www.mysite.com/login">Login</a></li>';
};
?>

Good luck :slight_smile:

that worked, thanks :slight_smile: