Solve the problem of Gravatar avatar image not displaying, causing website access to slow down

888u

Last update at :2024-06-18,Edit by888u

Basically all blog websites use Gravatar as avatar storage and display call. Recently, due to network delay issues, the website speed on overseas hosts has not been very fast, especially when online, the convulsions are more obvious. Similarly, if the loading of the Gravatar avatar used in our blog is not processed by default, we will also find that the official Gravatar website cannot be opened at present. What if we solve the avatar calling problem?

First, if we still need to use Gravatar avatar

function get_ssl_avatar($avatar) {$avatar = preg_replace(\\'/.*\\\\/avatar\\\\/(.*)\\\\s=([\\\\d] +)&.*/\\',\\\'\\',$avatar);return $avatar;}add_filter(\\'get_avatar\\', \\'get_ssl_avatar\\');

Add the above code to the FUNCTIONS.PHP page in the current WORDPRESS theme. Because HTTP cannot be accessed directly, adjust it to the path address of HTTPS.

Second, use local avatars

function my_avatar($avatar) {$tmp = strpos($avatar, \\'http\\');$g = substr($avatar, $tmp, strpos($avatar, \\"\\'\ \", $tmp) – $tmp);$tmp = strpos($g, \\'avatar/\\') + 7;$f = substr($g, $tmp, strpos($g, \\" \\", $tmp) – $tmp);$w = get_bloginfo(\\'wpurl\\');$e = ABSPATH .\\'avatar/\\'. $f .\\'.jpg\\ ';$t = 1209600;if ( !is_file($e) || (time() – filemtime($e)) > $t ) {copy(htmlspecialchars_decode($g), $e);} else $avatar = strtr($avatar, array($g => $w.\\'/avatar/\\'.$f.\\'.jpg\\'));if (filesize($e) < 500) copy( $w.\\'/avatar/default.jpg\\', $e);return $avatar;}add_filter(\\'get_avatar\\', \\'my_avatar\\');

Similarly, in the FUNCTIONS.PHP file, add the above code to cache the avatar locally. Similarly, use the avatar folder as the root directory. You can first put a default.jpg as a default avatar display image that does not exist.

Third, use third-party comment plug-ins

You can use third-party comment plug-ins to display avatars. Currently, there is no calling problem. Snail has also written an article before "Comments on Four Social Comment Systems". At present, Duosuo and Chang are the ones that are most used. In other words, the user experience of the former is not bad, but the server is down and unstable. The latter is based on Sohu. The interface is average, but the server is relatively stable.

In short, all problems that affect website speed need to be solved.

Recommended site searches: domain name price, how to check domain name registration number, foreign space, me domain name registration, com domain name price, asp host national mixed dial server, ip online query, overseas server, Hong Kong vps host,

Solve the problem of Gravatar avatar image not displaying, causing website access to slow down

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码