Home / Admin / Add aria-label to progress bar to improve WPForms accessibility
Duplicate Snippet

Embed Snippet on Your Site

Add aria-label to progress bar to improve WPForms accessibility

<10
Code Preview
php
<?php
/**
 * Fix WPForms Accessibility: Add aria-label to progress bar.
 */
function wpf_fix_wpforms_progressbar_aria() {
    ?>
    <script>
    jQuery(document).ready(function($) {
        // Target the specific WPForms progress bar container
        $('.wpforms-page-indicator.progress').each(function() {
            // Add the accessible name (aria-label)
            $(this).attr('aria-label', 'Form Page Progress');
        });
    });
    </script>
    <?php
}
// Use wp_footer with priority 99 to ensure this loads after WPForms scripts
add_action( 'wp_footer', 'wpf_fix_wpforms_progressbar_aria', 99 );
/**
 * Fix WPForms Accessibility: Change Section Divider h3 tags to h2.
 * This fixes the "skipped heading level" accessibility error.
 */
function wpf_fix_wpforms_heading_hierarchy() {
    ?>
    <script>
    jQuery(document).ready(function($) {
        // Target h3 elements specifically within WPForms divider fields
        $('.wpforms-field-divider h3').each(function() {
            var $original = $(this);
            
            // Create a new h2 element
            var $replacement = $('<h2 />');
            // Copy all attributes (id, class, aria-errormessage, etc.) 
            // from the original h3 to the new h2 to ensure form functionality remains
            $.each($original[0].attributes, function(i, attr) {
                $replacement.attr(attr.name, attr.value);
            });
            // Copy the text/html content inside the heading
            $replacement.html($original.html());
            // Replace the old h3 with the new h2
            $original.replaceWith($replacement);
        });
    });
    </script>
    <?php
}
// Load into footer with high priority
add_action( 'wp_footer', 'wpf_fix_wpforms_heading_hierarchy', 99 );

Comments

Add a Comment