0

I use this code to display the user profile in WordPress:

   <?php
   if ( is_user_logged_in() ) {
    $current_user = wp_get_current_user();
     if ( ($current_user instanceof WP_User) ) {
       echo '<div class="omid-header-proimg">'.get_avatar( $current_user->ID, 64 ).'</div>';
       echo '<div class="omid-header-protext">'.esc_html( $current_user->display_name ).'</div>';
       echo '<div class="omid-logpanel"><a href="https://test.com/panel">panel</a></div>';
    }
    }
   ?>

But when I want to use the following code for when the user is not logged in, the site will not be loaded. where is the problem from?

    <?php
   if ( is_user_logged_in() ) {
    $current_user = wp_get_current_user();
     if ( ($current_user instanceof WP_User) ) {
       echo '<div class="omid-header-proimg">'.get_avatar( $current_user->ID, 64 ).'</div>';
       echo '<div class="omid-header-protext">'.esc_html( $current_user->display_name ).'</div>';
       echo '<div class="omid-logpanel"><a href="https://test.com/panel">panel</a></div>';
    }
  }
  else {
    echo '<div class="omid-header-proimg"><img src="'. bloginfo('template_url') .'/images/omid-nonsignin.png"></div>'
    echo '<div class="omid-logpanel"><a href="https://test.com/panel">login</a></div>'
  }
?>
  • Keep in mind that bloginfo doesn't return the template url, it outputs the termplate URL, if you're inseting it into a string, use get_bloginfo instead. But in this case there is a much better function get_template_directory_uri() – Tom J Nowell Jul 2 at 17:47
2

Your last lines are missing semi-colons:

  echo '<div class="omid-header-proimg"><img src="'. bloginfo('template_url') .'/images/omid-nonsignin.png"></div>';
  echo '<div class="omid-logpanel"><a href="https://test.com/panel">login</a></div>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.