1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HTTPSのWordpressでGravatarのアバター画像を表示する

Posted at

http通信であれば下記のコードで表示されるのですが、サイト全体をHTTPS通信にするとMixed Contentとなりアバター画像が表示されなくなってしまいます。

<?php echo get_avatar(get_the_author_id(), 30); ?>

こう書いたら解決しました。

<img src="https://secure.gravatar.com/avatar/<?php echo md5(strtolower(trim(get_the_author_meta('user_email')))); ?>?s=30">

ユーザーのEメールを取得、trimでスペースを削除、strtolowerで小文字化、表記のゆれをなくしてからmd5でハッシュ化します。

30の数字は画像サイズです。調整して使ってください。

参考文献

Image Requests

Creating the Hash

もっとスマートな書き方があれば教えていただけると嬉しいです!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?