Until version 3.5, WordPress automatically added a title
attribute to all inserted images. While this hasn’t been part of core since 2011, there’s still a lot of older content that’s never been updated.
In addition to that, many plugins and themes still use the title attribute in numerous inappropriate contexts: input fields, images, links, and buttons among others.
Because the title
attribute is part of the accessible name calculations for assistive technology, WP Accessibility uses some moderately complex scripting to handle them.
Images
For images, WP Accessibility checks whether there is an alt attribute or not. If there is an alt attribute, then the title attribute is removed. If there is no alt attribute, the title is assigned as the alt attribute.
Links & Buttons
For links and buttons, WP Accessibility checks for an aria label or any contained element that has valid text, including images with alt attributes or text nodes. If any contained link text is found, then the title attribute is removed and no further action is taken. If no contained text is found, the title attribute is assigned as the aria-label.
Input Fields
For input fields, WP Accessibility checks for any valid label first: an aria-label, a field related using aria-labelledby
, an explicitly associated label
, or a wrapping label
element. If any of those are found and have valid text, then the title attribute is removed with no further action. If no label is found, then the title will be set as aria-label
for the input.