wordpress 评论头像如果没有设置的话,默认都是火车头的头像,下面代码可以实现头像的随机展示
/** * 为没有 Gravatar 头像的用户加载随机头像 */ add_filter( 'get_avatar' , 'inlojv_custom_avatar' , 10 , 5 ); function inlojv_custom_avatar( $avatar, $id_or_email, $size, $default, $alt) { global $comment; $email = !empty($comment->comment_author_email) ? $comment->comment_author_email : $id_or_email ; $email_hash = md5(strtolower(trim($email))); $random = mt_rand(11, 99); $src = ''.get_template_directory_uri().'/images/avatar/dedewp-avatar'. $random .'.jpg'; $avatar = "<a data-fancybox="gallery" href="//secure.gravatar.com/avatar/{$email_hash}?d=404"title="wordpress 评论用户头像随机显示办法分享" ><img class="aligncenter size-full wp-image" src="//secure.gravatar.com/avatar/{$email_hash}?d=404" alt="wordpress 评论用户头像随机显示办法分享" /></a>"; return $avatar; } */
当然了 你先要增加一些随机图片供展示。