Set alt image attributes for images and portraits in WordPress

Source: Internet
Author: User

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 ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.