Site logo

Archived topic

How to add a label to the Navigation Search form

6 replies · Started by webmaster on August 14, 2020

Viewing posts 1–7 of 7

Hi
To comply with the Accessibility Guidelines that will become mandatory for public bodies in September, I need to add a label to the Navigation Search form that you can enable when customising the layout.
There is no option to add a label when you enable the form.
Could you advise me how to add one?
Thanks
Gina

Hi there,

try adding this PHP Snippet to your site:

add_filter( 'generate_navigation_search_output', function() {
    printf(  
        '<form method="get" class="search-form navigation-search" action="%1$s">
	    <label for="nav-search">Search:</label>
            <input type="search" class="search-field" id="nav-search" value="%2$s" name="s" title="%3$s" />
            <input type="hidden" name="post_type" value="product" />
        </form>', 
        esc_url( home_url( '/' ) ), 
        esc_attr( get_search_query() ),   
        esc_attr_x( 'Search', 'label', 'generatepress' ) 
    ); 
} );

Many thanks for your suggestion, this has successfully added a label tag.
Thanks!

You're welcome

Hey David, by replacing your code i get the message "A form control has more than one label associated with it." from web accessibility. How can i solve this? thanks in advance, Stephan

Hi Stephan,

can you raise a new topic where you can share a link to your site so i can see whats causing that.

Done. thank you David

This archived topic is closed to new replies.