如何检查配置文件是否具有默认头像

问题描述 投票:0回答:1

如果有默认的gravatar,我想隐藏个人资料。我尝试了很多代码,但它们并没有给我带来丰硕的成果。因为有些图像来自媒体文件夹,有些来自'https://secure.gravatar.com/avatar/'。谁能告诉我如何检测这个东西?

wordpress avatar gravatar
1个回答
1
投票
The get_avatar() returns An img element for the user's avatar or false on failure. The function does not output anything; you have to echo the return value.

Please try below code to check if the profile has a default avatar.

if(!get_the_author_meta('ID')){
        // no img code here     
        echo 'no img code';
    }else{
        $gavar_url = get_avatar_url( $user_email);
        if(strpos($gavar_url,'gravatar.com')!==false){
            //no image code here 
        }else{
            echo get_avatar( get_the_author_meta('ID') , 80);
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.