简体   繁体   中英

How to integrate the user's avatar in code from Buddypress?

I have a template that display a bubble with an image in it. But I would like to replace this image by the logged in user's avatar from Wordpress.

How can I do that ?

Here is the code of my section :

<?php
    $latte_intro_avatar = get_theme_mod('latte_intro_avatar', get_template_directory_uri().'/assets/images/avatar.jpg' );
    $latte_intro_scroll = get_theme_mod('latte_intro_scroll', '#about' );
?>

        <section class="intro" id="intro">
            <div class="container">
                <div class="cover-container row">
                    <div class="inner cover col-md-12">
                    <?php if(!empty($latte_intro_avatar)) : ?>
                        <div class="avatar" style="background-image:url('<?php echo esc_url($latte_intro_avatar); ?>');"></div>
                    <?php endif; ?>
                        <h1 class="cover-heading"><?php bloginfo( 'name' ); ?></h1>
                        <p class="lead"><?php bloginfo( 'description' ); ?></p>
                        <?php if(!empty($latte_intro_scroll)) : ?>
                            <a href="<?php echo esc_url($latte_intro_scroll); ?>" class="arrow"><i class="fa fa-arrow-circle-down"></i></a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </section>

Found the solution :

<?php
    global $current_user;
    if ( is_user_logged_in() ):
        get_currentuserinfo();     
        echo get_avatar( $current_user->ID, 64 );
    endif;  
?>

Works like a charm. source : https://wordpress.stackexchange.com/questions/173626/display-avatar-of-user-profile-when-logged-in

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM