2015-08-20 36 views
0

如果用戶沒有自動生成的頭像,我該如何回退到默認圖像?Fallback Avatar Wordpress

這是我的代碼。

<?php 
    if (is_user_logged_in()) { 
     echo '<img class="avatar" src="'. wsl_get_user_custom_avatar ($current_user->ID) .'" alt="avatar"> Welcome '.$current_user->display_name.', Please help our community grow by liking and sharing! <br> <a class="logout" href="'. wp_logout_url() .'">Logout</a>'; } 
    else { 
     echo '<h2>1 Click Login</h2>'; 
    } 
    ?> 
    <?php do_action('wordpress_social_login'); ?> 

回答

1

是這樣的嗎?更改默認頭像的路徑,你喜歡...

<?php 
     if (is_user_logged_in()) { 
$avatarPath = wsl_get_user_custom_avatar ($current_user->ID)?wsl_get_user_custom_avatar ($current_user->ID):'http://img.thehobbyblogger.com/2012/08/mystery-man-avatar.png'; 
      echo '<img class="avatar" src="'.$avatarPath.'" alt="avatar"> Welcome '.$current_user->display_name.', Please help our community grow by liking and sharing! <br> <a class="logout" href="'. wp_logout_url() .'">Logout</a>'; } 
     else { 
      echo '<h2>1 Click Login</h2>'; 
     } 
     ?> 
     <?php do_action('wordpress_social_login'); ?> 
+0

這就是它!完善!非常感謝。 –