logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$5
Show login to users not logged in &welcome message when they are

I have the login looking pretty much how I want it to look, and it works. However, when a user logs in, it still has the login in form up there.

What I'd like to do is have the login form for users not logged in, but when ther are logged in, show some kind of welcome message.

Here is the temp site:

http://joe.gs

This question has been answered.

Joe Jenkins | 08/14/10 at 5:41am Edit


(3) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    08/14/10
    5:54am
    Baki Goxhaj says:

    Hi Joe,

    This code will do the magic:


    <?php
    if ( is_user_logged_in() ) {

    echo 'Welcome!';

    } else {

    // Your form's code goes here

    };
    ?>

    • 08/14/10 5:52am

      Joe Jenkins says:

      Thanks Baki,

      That seems straight forward but, of course being me, there has to be an error turn up.

      I'm using the following code:

      <?php

      if ( is_user_logged_in() ) {
      echo 'Welcome!';

      } else {
      <?php wp_login_form(); ?>

      };
      ?>


      But I get a white screen error telling me:

      Parse error: syntax error, unexpected '<' in /var/www/vhosts/joe.gs/httpdocs/wp-content/themes/Bloggers/header.php on line 41

      Line 41 is the php login form code. It works fine on its own.

    • 08/14/10 5:53am

      Joe Jenkins says:

      Ah, leave off the php bits inside php.

      That sorted it, thanks :o)

    • 08/14/10 5:53am

      Baki Goxhaj says:

      You have opening PHP tags insde PHP. Do this:


      <?php

      if ( is_user_logged_in() ) {

      echo 'Welcome!';

      } else {

      wp_login_form();

      };

      ?>

  • avatar
    Last edited:
    08/14/10
    5:50am
    Rashad Aliyev says:

    I gave you a code which made by me for other projects.

    You can integrate it your site. It's showing login form and if it's logged then show Welcome message, profile links and logged out. You can improve it.

    <?php if (!(current_user_can('level_0'))){ ?>


    <h3>Login</h3>
    <form action="<?php echo get_option('home'); ?>/wp-login.php" method="post">
    <input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="20" />
    <input type="password" name="pwd" id="pwd" size="20" />
    <input type="submit" name="submit" value="login" class="button" />
    <p>
    <label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember</label> | <a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">forget password (?)</a>
    <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
    </p>
    </form>

    </div>

    <div align="center" ><a id="girisbutton-a" href="<?php echo get_option('home'); ?>/wp-login.php?action=register">register</a></div>

    <?php } else { ?>
    <div><h3><?php echo $user_identity; ?></h3>
    <div><a href="<?php echo wp_logout_url(urlencode($_SERVER['REQUEST_URI'])); ?>">log out»</a></div>

    Welcome! </div>

    <a id="girisbutton-a" href="<?php echo get_option('home'); ?>/wp-admin/profile.php">look at profile</a>
    <?php }?>

  • avatar
    Last edited:
    08/14/10
    5:54am
    Ashfame says:

    Use this :

    <?php

    if ( is_user_logged_in() )
    {
    echo 'Welcome!';
    }
    else
    {
    wp_login_form();
    }

    ?>

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.