Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1033682
    travelstrong
    Participant

    Hi there,

    Using a child theme, I have added this code to my functions.php file to create a shortcode to pull through the current user’s gravatar:

    function theme_prefix_get_user_avatar() {
    
    	if ( is_user_logged_in() ) :
    		$current_user = wp_get_current_user();
    		$current_user_email = $current_user->user_email;
    		$current_user_name = $current_user->display_name;
    		$current_user_avatar = get_avatar( $current_user_email, 96, '', $current_user_name );
    		return $current_user_avatar;
    	endif;
    
    }
    
    add_shortcode('user_avatar', 'theme_prefix_get_user_avatar');
    

    I need to display the gravatar in the header (which I’m using as a fixed left sidebar), directly below my site’s logo, and above the navigation links.

    So my question is: how can insert either:

    <?php echo theme_prefix_get_user_avatar(); ?>

    or

    [user_avatar]

    into my sidebar in that position?

    Thanks in advance!

    Will

    #1033842
    Paul R
    Moderator

    Hi Will,

    Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

    #1033920
    travelstrong
    Participant

    Hi Paul,

    I’m actually doing this on a staging site run on a local server, so am unable to provide a URL unfortunately. Would screenshots help?

    Will

    #1034303
    Jade
    Moderator

    Hi Will,

    You can try adding a _navbar.php file in x-child/framework/views/global then add this code in the file:

    <?php
    
    // =============================================================================
    // VIEWS/GLOBAL/_NAVBAR.PHP
    // -----------------------------------------------------------------------------
    // Outputs the navbar.
    // =============================================================================
    
    $navbar_position = x_get_navbar_positioning();
    $logo_nav_layout = x_get_logo_navigation_layout();
    $is_one_page_nav = x_is_one_page_navigation();
    
    ?>
    
    <?php if ( ( $navbar_position == 'static-top' || $navbar_position == 'fixed-top' || $is_one_page_nav ) && $logo_nav_layout == 'stacked' ) : ?>
    
      <div class="x-logobar">
        <div class="x-logobar-inner">
          <div class="x-container max width">
            <?php x_get_view( 'global', '_brand' ); ?>
          </div>
        </div>
      </div>
    
      <div class="x-navbar-wrap">
        <div class="<?php x_navbar_class(); ?>">
          <div class="x-navbar-inner">
            <div class="x-container max width">
              <?php x_get_view( 'global', '_nav', 'primary' ); ?>
            </div>
          </div>
        </div>
      </div>
    
    <?php else : ?>
    
      <div class="x-navbar-wrap">
        <div class="<?php x_navbar_class(); ?>">
          <div class="x-navbar-inner">
            <div class="x-container max width">
              <?php x_get_view( 'global', '_brand' ); ?>
              <!-- Add the gravatar shortcode here -->
              <?php x_get_view( 'global', '_nav', 'primary' ); ?>
            </div>
          </div>
        </div>
      </div>
    
    <?php endif; ?>

    Please make sure to add your gravatar code in the area that says <!-- Add the gravatar shortcode here -->

    Hope this helps.

  • <script> jQuery(function($){ $("#no-reply-1033682 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>