WordPress uses Gravatar as the reviewer's profile picture, which should be well known. However, we do not know whether we have found that the Alt attribute of the Gravatar Avatar is null, which obviously does not comply with w3c standards. Zhou Liang provides a method to set the alt attribute for the WordPress Gravatar avatar.
Edit wp-uplodes/pluggable. php under the root directory of the website and find the get_avatar statement.
The code is as follows: |
Copy code |
Function get_avatar ($ id_or_email, $ size = '96 ', $ default = '', $ alt = false ){ If (! Get_option ('show _ avatars ')) Return false; If (false ===$ alt) $ Safe_alt = ''; Else $ Safe_alt = esc_attr ($ alt ); |
Modify it to the following code:
The code is as follows: |
Copy code |
Function get_avatar ($ id_or_email, $ size = '96 ', $ default = '', $ alt = false ){ If (! Get_option ('show _ avatars ')) Return false;
If (false ===$ alt) $ Safe_alt = 'gravatar '; // the Alt attribute is "Gravatar" // $ Safe_alt = get_comment_author ($ alt); // output the user name if you write it like this. The tested Alt attribute is "anonymous" Else $ Safe_alt = esc_attr ($ alt ); |
Well, now you can set the alt attribute for the WordPress Gravatar avatar.
Let's look at the wordpress quota of 10 thousand, and there will be a corresponding answer after a search, as shown below.
The code is as follows: |
Copy code |
Function photo_alt ($ c ){ Global $ post; // global quantity $ Title = $ post-> post_title; // Article title $ S = array ('/src = "(. + ?. (Jpg | bmp | png | jepg | gif) "/I '=> 'src =" $1 "alt ="'. $ title .'"'); Foreach ($ s as $ p => $ r ){ $ C = preg_replace ($ p, $ r, $ c ); } Return $ c; } Add_filter ('The _ content', 'Photo _ alt '); |