Title: javascript – Make WordPress Accessible

---

#  Tag Archives: javascript

 [  ](https://profiles.wordpress.org/joedolson/) [Joe Dolson](https://profiles.wordpress.org/joedolson/)
6:09 pm _on_ April 15, 2015     
Tags: ajax, ARIA, javascript   

# 󠀁[Let WordPress Speak: New in WordPress 4.2](https://make.wordpress.org/accessibility/2015/04/15/let-wordpress-speak-new-in-wordpress-4-2/)󠁿

_Written by Andrea Fercia & Joe Dolson_

WordPress 4.2 is shipping with a useful new JavaScriptJavaScript JavaScript or JS
is an object-oriented computer programming language commonly used to create interactive
effects within web browsers. WordPress makes extensive use of JS for a better user
experience. While PHP is executed on the server, JS executes within a user’s browser.
[https://www.javascript.com](https://www.javascript.com/) method: `wp.a11y.speak()`.
This is a utility to make it easy for WordPress coreCore Core is the set of software
required to run WordPress. The Core Development Team builds WordPress. to create
consistent methods for providing live updates for JavaScript events to users of 
screen readers – with the side benefit that developers of plug-ins and themes can
also make use of it either on the front or back end.

### Why.

In modern web development, updating discrete regions of a screen with JavaScript
is common. The use of AJAX responses in modern JavaScript-based User Interfaces 
allows web developers to create beautiful interfaces similar to Desktop applications
that don’t require pages to reload or refresh.

JavaScript can create great usability improvements for most users – but when content
is updated dynamically, it has the potential to introduce accessibilityAccessibility
Accessibility (commonly shortened to a11y) refers to the design of products, devices,
services, or environments for people with disabilities. The concept of accessible
design ensures both “direct access” (i.e. unassisted) and “indirect access” meaning
compatibility with a person’s assistive technology (for example, computer screen
readers). (https://en.wikipedia.org/wiki/Accessibility) issues. This is one of the
steps you can take to handle that problem.

### What.

When a portion of a page is updated with JavaScript, the update is usually highlighted
with animation and bright colors, and is easy to see. But if you don’t have the 
ability to see the screen, you don’t know this has happened, unless the updated 
region is marked as an ARIA-live region.

If this isn’t marked, there’s no notification for screen readers. But it’s also 
possible that all the region content will be announced after an update, if the ARIA
live region is too large. You want to provide users with just a simple, concise 
message.

### How.

That’s what `wp.a11y.speak()` is meant for. It’s a simple tool that creates and 
appends an ARIA live notifications area to the `<body>` element where developers
can dispatch text messages. Assistive technologies will automatically announce any
text change in this area. This ARIA live region has an ARIA role of “status” so 
it has an implicit `aria-live` value of `polite` and an implicit `aria-atomic` value
of `true`.

This means assistive technologies will notify users of updates but generally do 
not interrupt the current task, and updates take low priority. If you’re creating
an application with higher priority updates (such as a notification that their current
session is about to expire, for example), then you’ll want to create your own method
with an `aria-live` value of `assertive`.

###  How do I use this?

 * enqueue ‘wp-a11yAccessibility Accessibility (commonly shortened to a11y) refers
   to the design of products, devices, services, or environments for people with
   disabilities. The concept of accessible design ensures both “direct access” (
   i.e. unassisted) and “indirect access” meaning compatibility with a person’s 
   assistive technology (for example, computer screen readers). (https://en.wikipedia.
   org/wiki/Accessibility)’ from your pluginPlugin A plugin is a piece of software
   containing a group of functions that can be added to a WordPress website. They
   can extend functionality or add new features to your WordPress websites. WordPress
   plugins are written in the PHP programming language and integrate seamlessly 
   with WordPress. These can be free in the WordPress.org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
   or can be cost-based plugin from a third-party. or theme or set it as a dependency
   of the script that generates updates
 * on DOM ready, pass a translatable string to `wp.a11y.speak()`: `wp.a11y.speak(
   mystring );`

    ```
    add_action( 'wp_enqueue_scripts', 'yourprefix_a11y' );
    function yourprefix_a11y() {
    	wp_enqueue_script( 'wp-a11y' );
    }
    ```

or

    ```
    add_action( 'wp_enqueue_scripts', 'yourprefix_ajax' );
    function yourprefix_ajax() {
    	wp_enqueue_script( 'yourprefix.ajax', get_template_directory_uri() . '/js/ajax.js', array( 'wp-a11y' ) );
    }
    ```

For an implementation example, take a look at `wp-admin/js/updates.js`. An important
note: `wp.a11y.speak()` is only available after DOM ready, so be sure not to call
it earlier!

If you’re intending to use this in your theme, you should take note that your theme
should also support the core class `.screen-reader-text`, which is used in the inserted
content. [Read more about screen reader text](https://make.wordpress.org/accessibility/2015/02/09/hiding-text-for-screen-readers-with-wordpress-core/).

### References and further reading

 * [Documentation on `aria-live`](http://www.w3.org/TR/wai-aria/states_and_properties#aria-live)
 * [Documentation on `aria-atomic`](http://www.w3.org/TR/wai-aria/states_and_properties#aria-atomic)
 * [Web Accessibility Initiative: Introduction to ARIA](http://www.w3.org/WAI/intro/aria.php)
 * [WebAIM: Techniques in AJAX](http://webaim.org/techniques/ajax/)

[#ajax](https://make.wordpress.org/accessibility/tag/ajax/), [#aria](https://make.wordpress.org/accessibility/tag/aria/),
[#javascript](https://make.wordpress.org/accessibility/tag/javascript/)