解决调用远程Gravatar头像图片不显示问题
Gravatar头像是现在博客通用的一个调用方法了,很多朋友的个人博客都使用了Gravatar头像了,但最近有很多站长发现Gravatar头像打开缓慢了,那么我们要如何解决Gravatar图片打不开或者打开慢的问题呢?下面来看看吧。
第一、如果我们还需要使用Gravatar头像
<?php function get_ssl_avatar($avatar) { $avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img class="avatar avatar-$2 lazy" src="/static/imghw/default1.png" data-src="https://secure.gravatar.com/avatar/$1?s=$2" height="$2" style="max-width:90%" alt="解决调用远程Gravatar头像图片不显示问题 " >',$avatar); return $avatar; } add_filter('get_avatar', 'get_ssl_avatar');
在当前WORDPRESS主题中的FUNCTIONS.PHP页面中加入上面的代码,因为HTTP直接访问不了,这里调整为HTTPS的路径地址。
第二、使用本地头像
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');
同样的,在FUNCTIONS.PHP文件中,加入上面的代码,把头像缓存本地,同样的使用avatar文件夹作为根目录,可以先放入一个default.jpg作为默认不存在的头像展示图片。
第三、使用第三方评论插件
使用第三方评论插件可以展示头像的,目前不存在调用问题,之前老左也写过一篇"点评四款社会化评论系统",目前使用较多的还是多说和畅言,前者用户体验还可以,就是服务器宕机不稳定。后者基于搜狐提供的,界面一般,但服务器是比较稳定的。
本文地址:
转载随意,但请附上文章地址:-)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











This article will explain in detail the ASCII value of the first character of the string returned by PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP returns the ASCII value of the first character of a string Introduction In PHP, getting the ASCII value of the first character of a string is a common operation that involves basic knowledge of string processing and character encoding. ASCII values are used to represent the numeric value of characters in computer systems and are critical for character comparison, data transmission and storage. The process of getting the ASCII value of the first character of a string involves the following steps: Get String: Determine the string for which you want to get the ASCII value. It can be a variable or a string constant

This article will explain in detail how PHP returns the string from the start position to the end position of a string in another string. The editor thinks it is quite practical, so I share it with you as a reference. I hope you will finish reading this article. You can gain something from this article. Use the substr() function in PHP to extract substrings from a string. The substr() function can extract characters within a specified range from a string. The syntax is as follows: substr(string,start,length) where: string: the original string from which the substring is to be extracted. start: The index of the starting position of the substring (starting from 0). length (optional): The length of the substring. If not specified, then

Use the PHP function "substr" to obtain the substring of a string. In PHP programming, you often encounter situations where you need to obtain part of the content of a string. At this time, we can use PHP's built-in function "substr" to achieve this. This article explains how to use the "substr" function to get a substring of a string and provides some code examples. 1. Basic usage of the substr function The substr function is used to obtain a substring of a specified length from a string. Its basic syntax is as follows: substr(

Understand the substr() function in PHP for intercepting strings. In the PHP language, the substr() function is a very useful string processing function, which can be used to intercept string fragments at a specified position and length. The substr() function accepts three parameters: the string to be intercepted, the starting position of the interception, and the length of the interception. Below we will introduce the use of the substr() function in detail and give specific code examples. Basic usage of substr() function substr() function

Solutions for invalid PHPmb_substr function When developing PHP applications, the mb_substr function is often used to intercept strings. However, sometimes you may encounter situations where the mb_substr function is invalid, mainly due to character encoding issues in different environments. In order to solve this problem, we need to effectively handle the mb_substr function. A common solution is to ensure that the mb_substr function can

This article will explain in detail how PHP converts the first letter of a string to lowercase. I think it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. Converting the first letter of a PHP string to lowercase Introduction In PHP, converting the first letter of a string to lowercase is a common operation. This can be achieved by using the built-in function lcfirst() or the string operator strtolower(). This guide will dive into both approaches, providing example code and best practices. Method 1: Use the lcfirst() function The lcfirst() function is specifically designed to convert the first letter of a string to lowercase while leaving the rest of the characters unchanged. Its syntax is as follows: st

This article will explain in detail how PHP returns a string starting from the last occurrence of a string in another string to the end. The editor thinks it is quite practical, so I share it with you as a reference. I hope you will finish reading it. You can learn something from this article. Get the string from the last occurrence of a string to the end in PHP Question: How to use PHP to get the substring from the last occurrence of a string to the end of another string? Solution: There are two main ways in PHP to get the substring from the last occurrence of a string to the end: 1. Use the strrpos() function The strrpos() function returns the last occurrence of a string in another string bit

The substr_replace() function in the PHP language is a very practical string processing function, which can be used to replace a substring of a specified length. The syntax of the substr_replace() function is as follows: substr_replace($string,$replacement,$start[,$length]); where $string represents the original string to be replaced, and $replacement represents the replaced string.
