Reputation: 45
I'm trying to do this:
<?php
global $current_user;
get_currentuserinfo();
if ( is_user_logged_in() ) {
echo '<span class="ciao">HELLO ' . $current_user->user_login . '</span>'; "\n";
echo '<a href=" . wp_logout_url( home_url() ); . " title="Logout">Logout</a>';
}
else {
echo '<a href=" . wp_login_url( get_permalink() ); . " title="Login">Login</a>';
}
?>
The problem is that href gives me back the empty value: wp_logout_url( home_url() );
When I use this WORDPRESS call outside the echo it works good, like this eg:
<a href="<?php echo wp_logout_url( home_url() ); ?>">LOGOUT</a>
How can i write this ??
Upvotes: 1
Views: 24698
Reputation: 1
Here the correct option
<?php
global $current_user;
get_currentuserinfo();
if ( is_user_logged_in() ) {
echo '<span class="ciao">HELLO ' . $current_user->user_login . '</span>\n';
echo '<a href="' . wp_logout_url( home_url() ) . '" title="Logout">Logout</a>';
} else {
echo '<a href="' . wp_login_url( get_permalink() ) . '" title="Login">Login</a>';
}
?>
Upvotes: 0
Reputation: 45
None of those was, but I appreciated. This works well:
'<a href="'.wp_logout_url( home_url() ).'">text</a>
Upvotes: 2
Reputation: 20047
It's because you've not ended you string
You'd want to use the following:
echo "<a href=\"" . wp_login_url( get_permalink() ); . "\"/>;
Upvotes: 0
Reputation: 3369
I think what you want is this:
<?php global $current_user;
get_currentuserinfo();
if ( is_user_logged_in() ) { echo '<span class="ciao">HELLO ' . $current_user->user_login . '</span>'; "\n";
echo '<a href="' . wp_logout_url( home_url() ); . '" title="Logout">Logout</a>'; } else { echo '<a href="' . wp_login_url( get_permalink() ); . '" title="Login">Login</a>'; } ?>
The different is the string is closed before the result of wp_logout_url() is concatenated with it
Upvotes: 0
Reputation: 989
echo '<a href=" . wp_logout_url( home_url() ); . " title="Logout">Logout</a>';
Needs to be changed to
echo '<a href="' . wp_logout_url( home_url() ) . '" title="Logout">Logout</a>';
String started with single quote needs to be closed with single quote.
Upvotes: 0
Reputation: 3282
echo '<a href="' . wp_logout_url( home_url() ) . '" title="Logout">Logout</a>';
Upvotes: 3