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
|
1 Answer
Reset to default 3Your 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
bloginfo
doesn't return the template url, it outputs the termplate URL, if you're inseting it into a string, useget_bloginfo
instead. But in this case there is a much better functionget_template_directory_uri()
– Tom J Nowell ♦ Commented Jul 2, 2019 at 17:47