login - Problems with is_user_logged_in() | Function in WP

I use this code to display the user profile in WordPress:<?phpif ( is_user_logged_in() ) {$current_user = wp_get_curr

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="">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="">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="">login</a></div>'
  }
?>

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/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/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/panel">login</a></div>'
  }
?>
Share Improve this question asked Jul 2, 2019 at 16:22 omid chahardoliomid chahardoli 191 silver badge9 bronze badges 1
  • 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 Commented Jul 2, 2019 at 17:47
Add a comment  | 

1 Answer 1

Reset to default 3

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/panel">login</a></div>';

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745351083a4623835.html

相关推荐

  • login - Problems with is_user_logged_in() | Function in WP

    I use this code to display the user profile in WordPress:<?phpif ( is_user_logged_in() ) {$current_user = wp_get_curr

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信