Echoing a function?

Discussion in 'PHP' started by Mafia Penguin, Apr 24, 2011.

  1. #1
    Hey Everyone,

    I'm pretty novice when it comes to understanding php code, so it came to the point where, something i'm sure is quite simple, has me scratching my head.

    This is what im trying to accomplish. When a user is logged in then the message Welcome Registered Guest... & the function <?php echo wp_logout_url(); ?> is displayed, and when there not then it displays the log in function and Welcome Visitor.

    
    <?php
    if ( is_user_logged_in() ) {
        echo 'Welcome, registered user!';
        echo '<a href="<?php echo wp_logout_url(); ?>" title="Logout">Logout</a>';
    } else {
        echo 'Welcome, visitor!';
    echo '<a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>';
    };
    ?>
    PHP:
    Anyone have an idea of how i can do this?

    Thanks, http://www.filmhammer.com
     
    Mafia Penguin, Apr 24, 2011 IP
  2. salmanshafiq

    salmanshafiq Well-Known Member

    Messages:
    260
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    128
    #2
    Below is the correct code ...

    
    <?php
    if ( is_user_logged_in() ) {
        echo 'Welcome, registered user!';
        echo '<a href="'.wp_logout_url().'" title="Logout">Logout</a>';
    } else {
        echo 'Welcome, visitor!';
    echo '<a href="'.wp_login_url( get_permalink() ).'" title="Login">Login</a>';
    }
    ?>
    
    Code (markup):
     
    salmanshafiq, Apr 24, 2011 IP
    Mafia Penguin likes this.
  3. Mafia Penguin

    Mafia Penguin Peon

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sweet. Thanks for the help. :)
     
    Mafia Penguin, Apr 24, 2011 IP
  4. Mafia Penguin

    Mafia Penguin Peon

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I don't s'pose you know how to wrap a div around this function ' wp_login_form();' in the code do you?

    
    <?php
    if ( is_user_logged_in() ) {
        wp_login_form();
        echo 'Welcome, visitor!';
        echo '<div class="art-admin"><a href="'.wp_logout_url().'" title="Logout">Logout</a></div>';
        echo '<div class="art-admin"><a href="'.get_admin_url().'" title="Admin">Admin</a></div>';
     
    } else {
       
    echo '<a href="'.wp_login_url( get_permalink() ).'" title="Login">Login</a>';
    }
    ?>
    
    PHP:
     
    Mafia Penguin, Apr 26, 2011 IP