Support » How-To and Troubleshooting » Logout Fuction in an echo statement?

Logout Fuction in an echo statement?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Works for me….

    Are you using wordpress 2.7.1? I get this error:

    You are attempting to log out of Complimedia Online Blog
    Please try again.

    How Can I add the correct logout link (<?php echo wp_logout_url(get_permalink()); ?>) inside the echo statement?

    I would also really like to check the registered users name and display it inside the echo statement but I do not know how.

    Something like this:

    if (is_user_logged_in()){
               echo "<h3>Welcome, wt_get_user_name();!</h3>
    <li><a href='wp_logout_url(get_permalink());' title='Log out of this account'>Log out</a></li>

    Yep on 2.7.1 …. local and remote…

    Your first piece of code functions, so if you’re having issues with that it might be how you’re placing your code…

    WP functions behave differently depending on what you use, some return content, some need to be echo’ed…

    I’d check the docs for any functions you want to use…


    I don’t think that’s even a WordPress function…

    Like i said, there’s nothing wrong with the first piece of code you posted… it works…

    The first piece of code I used does _NOT_ work. Please see this thread: http://wordpress.org/support/topic/225695?replies=8

    Basically I want to echo out wp_logout_url(get_permalink()); but I don’t know how to do that in php! I’ve tried making that a variable and inserting the $var into the echo statement but that was unsuccessful as well.

    wt_get_user_name was found on this site: http://www.web-templates.nu/2008/08/27/get-user-name/

    once again I want to put that function in the echo statement.

    So try a few tests…

    Some functions return content, others need to be echo’ed…



    echo a_function();

    And see what comes up on the page for you…

    The most common problem i see with WordPress is people switching in and out incorrectly…

    <?php some code <?php something else ?> blah blah blah ?>

    The original code you posted worked without a problem on my local 2.7.1 install.

    It might just be your usuage that isn’t quite working, and like i said try plonking the code somewhere for testing, then again with an echo…

    Test each variable, each function and see what value they return before combining them.

    Thanks t31os, I figured it out!

    I used a $var to hold the outcome of the funtions in seperate php tags. Then I echo’d the $var.

    $logout = wp_logout_url(get_permalink());
    $username = wt_get_user_name();
      if (is_user_logged_in()){
               echo "Welcome, $username!<a href='http://blog.complimedia.com/wp-admin/'>Your Dashboard</a><a href='$logout' title='Log out of this account'>Log out</a>";
             else {
               echo "Welcome, guest!";

    Also in case your wondering how I got the username I created the function with this code

    <?php function wt_get_user_name()
    	global $userdata;
    	return $userdata->user_login;
    } ?>

    Initially missed this reply (WP Forum post tracking seems off – apparently i have not started a topic before :-s )…


    Nice to see you got it working matey…. 😉

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Logout Fuction in an echo statement?’ is closed to new replies.