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.

Webflow Price Increases

Webflow's recent price increase of approximately 44% for its CMS plans has sparked significant reactions among its user base, particularly among freelancers, agencies, and developers. Here are some key points and side effects based on user feedback: User Reactions and...

NXDOMAIN and DNS_PROBE_FINISHED_NXDOMAIN

An NXDOMAIN error, which stands for “Non-Existent Domain,” occurs when a domain name cannot be resolved by DNS servers. This error is common in various contexts, including WordPress sites.

9 Trends & Flexes In 2024 Web Design

The landscape of web design continues to evolve, embracing new technologies and design philosophies that enhance user experience, accessibility, and visual appeal.

Give Marketers A Perk: A Marketing Job WITHOUT Website Management

With all of the talk of workplace overload and the heavy job requirements, taking something off of a marketer’s plate provides two big wins: it give the marketer more breathing room to accomplish the important things in their job; and it offers the business owner some continuity on the public face of their brand– their website. Here’s our exhaustive list of ways a WordPress maintenance plan can help a marketer do their job better.

The Juggling Act of Priorities for a WordPress Developer

Being a WordPress developer is akin to performing a delicate juggling act. With numerous tasks requiring attention, from translating visual designs into functional websites to ensuring optimal performance and security, managing priorities becomes crucial. We put a lot of effort putting together an in-depth look at how a WordPress developer can effectively balance these responsibilities.

SEO In the World of Artificial Intelligence

Getting An Audience via Search Engine Optimized Content There's a new sheriff in town. Its name is "Search Generative Experience." For a while now, Google has been moving from being the world's biggest index of web pages do being the destination unto itself. Its...

Stripe vs Square vs Paypal

Here’s a quick rundown of these three major ecommerce providers and how they compare to each other. In my 25+ years of ecommerce rollouts, I have dealt with Stripe, Square and Paypal implementations as well as deployments with other providers like Authorize.net, Beanstream (WorldPay), Moneris and others. I really think the three in this article can satisfy most use cases.

Five Tips For AI In Content Creation

There’s a lot to consider about the practical aspects of creating content with AI but also the creative collaboration between human intelligence and artificial intelligence.

Understanding CSS Media Queries

CSS media queries are a powerful tool that allow you to apply different styles based on the characteristics of the device or viewport. They enable you to create responsive designs that adapt to different screen sizes, resolutions, and device types (desktop, tablet, mobile, etc.).

Spring into 2024: 30 Great Backlink Sources

Creating backlinks, which are links from one website to another, is a fundamental aspect of search engine optimization (SEO). They act as a "vote of confidence" from one site to another, indicating to search engines that the content is valuable, credible, and useful....

Getting More from Your CRM: Integrating GlueUp with WordPress

Customer relationship management (CRM) systems like GlueUp are invaluable for managing contacts, deals, and business relationships. However, the data in these systems often remains locked away, unseen by your wider customer base. Integrating your CRM with your...

Empowering Legal Advocacy Through Digital Solutions

In an era where digital presence is crucial, Web321 stands at the forefront of offering custom web solutions tailored for groups embarking on legal advocacy, particularly those initiating or involved in class-action lawsuits. Our expertise caters to the unique needs...

What’s the Deal With Quality Content?

What makes content high-quality? When it comes to content marketing, quality goes beyond surface metrics like word count or citations. True quality lies in how well content achieves its purpose and connects with readers. Does it align with marketing goals? Resonate...