According to the feedback from the network users, through the use of well-known social comment service providers to say that the provision of domestic Gravatar services, replace the default Gravatar function can solve the problem, and the access speed is very good.
Workaround 1: Use Gravatar HTTPS (apply to any topic)
In the topic directory, locate and open the functions.php file, and then copy the following code into the file:
The code is as follows |
Copy Code |
Hackgravatatr function Wpyou_get_ssl_avatar ($avatar) { $avatar = Preg_replace ('/.*\/avatar\/(. *) \?s= ([\d]+) &.*/', ' return $avatar; } Add_filter (' Get_avatar ', ' Wpyou_get_ssl_avatar '); |
Workaround 2: Use the multi-say Avatar library for replacement (for any subject)
In the topic directory, locate and open the functions.php file, and then copy the following code into the file:
The code is as follows |
Copy Code |
Hackgravatatr function Wpyou_get_avatar ($avatar) { $avatar = Str_replace (Array ("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), " Gravatar.duoshuo.com ", $avatar); return $avatar; } Add_filter (' Get_avatar ', ' Wpyou_get_avatar ', 10, 3); |
The code is correctly added to the theme of the functions.php file can be used to provide more than the domestic Gravatar service, so that the perfect solution to the problem.
Workaround 3: Local cache Avatar
3.1, set up a cache directory
Set up a folder in the Wp-content directory, named Avatar, and set the permissions for the folder to 0755 (if 0755 is not possible, try 0777).
3.2, set the default avatar
Prepare a default avatar with a size fit, named "Default.jpg", and put it in the Avatar folder.
3.3. Add Cache Code
In the topic directory, locate and open the functions.php file, and then copy the following code into the file:
The code is as follows |
Copy Code |
//Hackgravatatr Function Wpyou_localcache_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;/Set 14 days, unit: Seconds if (!is_file ($e) | | (Time ()-Filemtime ($e)) > $t) {//When avatar does not exist or files exceed 14 days to update copy (Htmlspecialchars_decode ($g), $e); Else $avatar = s TRTR ($avatar, Array ($g => $w. '/avatar/'. $f. jpg ')); if (filesize ($e) <) copy ($w. '/avatar/default.jpg ', $e); return $avatar; } Add_filter (' Get_avatar ', ' Wpyou_localcache_avatar '); |