How to Add aria-label And alt Tags to Your Divi Search Bar

by | Mar 28, 2023 | Business

Some of the code in Divi isn’t hooked into WordPress’ filter and action hooks. A good example: the menu system, especially the Search box. It needed WCAG descriptive tags and labels for the search open and close button.

The et_core_esc_previously() Function

et_core_esc_previously() is a function that is used in the Divi theme from Elegant Themes. The purpose of this function is to sanitize input data by escaping special characters, such as quotes and angle brackets, to prevent potential security vulnerabilities like cross-site scripting (XSS) attacks.

The function takes a single parameter, which is the data to be sanitized. It then applies a series of filters to the data to escape any characters that could potentially be used for malicious purposes. The sanitized data is then returned by the function.
The et_core_esc_previously() function is one of the Divi core functions. In the code base, it checked to see if the function as already been defined. If it has, it simply passes through the value. For the sake of adding labels, I added a custom version of this function my child theme’s functions.php file (see below). I looked for a string that surrounds where I want to add in the aria-label and alt tag. The str_replace() function was used to find-replace labels changes into place.

if(!(function_exists('et_core_esc_previously'))) {
   function et_core_esc_previously( $passthru ) {
       $passthru = str_replace('class="et_pb_menu__icon et_pb_menu__close-search-button"></button>', 'class="et_pb_menu__icon et_pb_menu__close-search-button" alt="close search" aria-label="close search"></button>', $passthru);
       $passthru = str_replace('et_pb_menu__search-button"></button>', 'et_pb_menu__search-button" alt="open search" aria-label="open search"></button>', $passthru);
       return $passthru;
   }
}

What is WCAG?

WCAG stands for Web Content Accessibility Guidelines: a set of guidelines from the World Wide Web Consortium (W3C) to make web content more accessible to people with disabilities.

The guidelines are organized into three levels of conformance: A, AA, and AAA. Level A includes the most basic guidelines for web accessibility, while level AAA includes the most advanced guidelines. Achieving level AA compliance is considered the industry standard for web accessibility.

WCAG guidelines cover a wide range of topics, including text alternatives for non-text content, keyboard accessibility, color contrast, language markup, and navigation. By following these guidelines, website owners can ensure that their content is accessible to people with disabilities, including those who are blind or visually impaired, deaf or hard of hearing, or have physical or cognitive disabilities.

In many countries, adherence to the WCAG guidelines is legally required for government and public sector websites. Even for private sector websites, compliance with WCAG is becoming increasingly important to ensure that all users can access web content. Best of all: it’s a set of good practices. WCAG compliant sites attract more visitors. A WCAG compliant site speaks more clearly to search engine spiders and AI agents.

 

How did I find this?

The starting point: the output. From there, I looked backwards. I looked at the HTML and found the ‘close-search-button’ phrase. I searched all of the Divi parent theme files for that phrase. Once found, I looked for the function that called that code. I found the function that called that function, et_core_esc_previously(). This function is referenced a number of times, so it’s a decent function to work with the get the HTML to output different code.

An Old Dog With A Few Tricks: The Dogpile Search Engine

Dogpile, a name that might conjure up images of the last time you strolled through a busy park, has a rich history as a metasearch engine. Established in 1996 by Aaron Flin, a research attorney, Dogpile was born out of frustration with the search engines of the time....

Calligo Going Away And What You Can Do About Your Website

March 1st is coming up fast and Calligo (www.calligo.io) clients have to find somewhere for their sites to live. This from Calligo : Important notice about your website and mail service from Calligo (previously 3 Peaks / Pacific Online) From 1st March 2021, you will...

17 Ways To Win at Growth Hacking 

  Growth Hacking is a great option for anyone looking to grow their business fast! For anyone unfamiliar with the term, growth hacking refers to a series of techniques used to add social media followers rapidly and with minimum investment on your part. As growth...

Play Twenty Questions With Your Website Decisions

What is it that sets one site from another? In short, brand optimization: knowing what you want to present to your potential client and how you’re going to present it. To get there, and create the online performance your brand deserves, you need to consider some important questions.

Keeping Up With Google Algorithms

Google’s algorithm is known to have core changes every few months to improve the quality of search results – what does this mean for you and your website? With every change to the algorithm, if not detected immediately, can lead to severe impacts on your website...

Web Maintenance Checklist

If you own a site, whether it is for personal use as a blog or you use it for your business, the site must be maintained frequently. The system is constantly updated and if you do not take enough care of your site through proper web maintenance, you will not attract...

WordPress: How Popular Is It?

WordPress has become a global marvel and it has taken a long leap since its release in 2003. From the 1st version of WordPress in 2003, it has been growing considerably even today. Being the most superior CMS in this industry, WordPress stands above its rival brands...

Web Presence Grant from the NASE Growth Grant in 2020

Web Presence Assistance provides a non-repayable contribution to Prince Edward Island businesses to assist them in establishing a presence on the Internet. The purpose of this assistance is to help Island companies increase business by creating a website to establish...

Web Presence Assistance From Innovation Prince Edward Island

Web Presence Assistance provides a non-repayable contribution to Prince Edward Island businesses to assist them in establishing a presence on the Internet. The purpose of this assistance is to help Island companies increase business by creating a website to establish...