Forums

[resolved] PHP for if first_name is present, echo x else echo y (3 posts)

  1. benfranklin
    Member
    Posted 2 years ago #

    I basically just need to know how to check to see if a logged in user has a first name entered or not, and if they do echo "show" which is associated with a display: inline class and if it's not present just don't print anything or print hide which is associated with a style of display: hide ... so I can show or hide name depending on whether it is present or not.

  2. benfranklin
    Member
    Posted 2 years ago #

    Nevermind. I was being dumb. Here is what I did to solve this:

    Welcome<span class="hide<?php global $current_user; get_currentuserinfo(); if ($current_user->user_firstname == true) { echo show; } ?>">&nbsp;<? echo "$current_user->user_firstname" ?></span>!

    Works well if you have hide as a style that hides and hideshow a style that shows.

  3. MichaelH
    Volunteer
    Posted 2 years ago #

    Just missed it...

    <?php
    if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
    if ( $userdata->first_name ) {
    echo ' You have a first name of '. $userdata->first_name;
    } else {
    echo ' Please, visit your profile page and enter a First Name.';
    }
    } else {
    echo 'Welcome, visitor!';
    };
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.