[Support request] How to add a label to the Navigation Search form

Home Forums Support [Support request] How to add a label to the Navigation Search form

Home Forums Support How to add a label to the Navigation Search form

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1402205
    webmaster

    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

    #1402625
    David
    Staff
    Customer Support

    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' ) 
        ); 
    } );
    #1406235
    webmaster

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

    #1406387
    David
    Staff
    Customer Support

    You’re welcome

    #1798535
    Stephan

    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

    #1798587
    David
    Staff
    Customer Support

    Hi Stephan,

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

    #1798802
    Stephan

    Done. thank you David

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.