mari
February 28, 2011, 10:22am
1
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/<?php echo wp_logout_url(); ?>
its echoing the php code instead of the url
what am i doing wrong :x
Immerse
February 28, 2011, 10:39am
2
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