Avatar Short Code

Is there a short code for Avatar so that I can have someone’s image appear in the Welcome Message in Theme settings. If not, what would be another way to achieve this?

  • DavidM
    • DEV MAN’s Mascot

    Hi y3kgeek,

    That would actually be more of a general WordPress question, a potentially very useful one I think. As such I went and threw together the following:

    <?php

    function logged_in_user_avatar_shortcode() {
    if ( is_user_logged_in() ) {
    global $current_user;
    get_currentuserinfo();
    return get_avatar( $current_user->ID );
    }
    }
    add_shortcode('logged-in-user-avatar', 'logged_in_user_avatar_shortcode');

    ?>

    You can add that to your theme’s functions.php file or better yet, wrap that with the plugin header code and make a plugin out of it.

    You’d then use the shortcode [logged-in-user-avatar] where you like in your content.

    The get_avatar() method has options associated with it, such as $size, which you’ll find more details on at the following:

    http://codex.wordpress.org/Function_Reference/get_avatar

    Hope this helps!

    -David

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.