• Here is my situation. I am currently working on a custom theme and there is one issue that I cannot seem to resolve.

    Basically, I want to use the user_identity function on the header.php file for a user bar.

    Here is my code:

    <!-- User Start -->
    
    <?php if ( $user_ID ) : ?>
    
    Welcome <b><?php echo $user_identity; ?></b>!
    ( <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout">Log Out</a> | <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php">Profile</a><?php wp_register(); ?> )
    
    <?php else : ?>
    
    Welcome <b>Guest</b>!
    ( <a href="<?php echo get_option('siteurl'); ?>/wp-login.php">Log In</a><?php wp_register(); ?> )
    
    <?php endif; ?>
    
    <!-- User End -->

    I know that my coding isn’t the most optimized but that wouldn’t be the reason for the function to not work.

    I would be most grateful if someone could assist me in resolving this issue.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I found your post on Google, and figured out a painfully simple solution on my own.
    <!-- User Start -->

    <?php if ( $user_ID ) :

    // here's the kicker
    global $user_identity;
    // really. that's it. ?>

    Welcome <b><?php echo $user_identity; ?></b>!
    ( <a href="/wp-login.php?action=logout">Log Out</a> | <a href="/wp-admin/profile.php">Profile</a><?php wp_register(); ?> )

    <?php else : ?>

    Welcome <b>Guest</b>!
    ( <a href="/wp-login.php">Log In</><?php wp_register(); ?> )

    <?php endif; ?>

    <!-- User End --></a>

    Easy enough, right? Cheers.

    THIS is what I was looking for. Thanks!

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    This works pretty much anywhere:

    $user = wp_get_current_user();
    if ($user) {
    //user is logged in, $user->ID will be their ID, etc..
    var_dump($user); // shows everything about them and all their variables
    }

    This works great, but it doesn’t seem to work in the header.php if I have an embedded Gallery2 in that page (using WPG2). It seems to think no one is logged in, even though they are. Any suggestions? It works fine if it is simply a wordpress page without the embedded content. I’m trying to figure a way around this.

    culvejc’s string works great for me, too. I was just wondering how to modify it so it only display’s the user’s first name instead of their full name.

    Thoughts?

    For whiner karnesb, after DAYS of email harassment ??

    $user_info = get_userdata($user_ID);
    echo $user_info->first_name;

    Cheers.

    Jon

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Getting User Identity Function To Work On header.php’ is closed to new replies.