[Resolved] Add Label Element to Form Control

Home Forums Support [Resolved] Add Label Element to Form Control

Home Forums Support Add Label Element to Form Control

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1606930
    Jesse

    Hello,

    This line of HTML is output on every page twice:

    <input type="search" class="search-field" value="" name="s" title="Search">

    I need to assign the <label> element to that form control as described here:

    https://www.w3.org/WAI/tutorials/forms/labels/

    So basically, the output should look something like this:

    <input type="search" class="search-field" value="" name="s" title="Search">
    <label for="s">Search</label>

    How can I accomplish this?

    Best regards,
    Jesse

    #1607470
    Elvin
    Staff
    Customer Support

    Hi,

    This line of HTML is output on every page twice:

    It’s rendered twice because the mobile header is enabled. Mobile header is its own independent header with its own search form so it will create its own <input> tag.

    As for changing how the nav search output, generate_navigation_search_output filter should help.

    Example: (adding <label for="s">Search</label> )

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

    Or edit the markup within the filter to your preference.

    A wise man once said:
    "Have you cleared your cache?"

    #1607870
    Jesse

    Hello,

    I added that code as a snippet, and it crashed my site as soon as I saved it. I had to restore a previous backup to get back in. I was completely locked out due to a critical site error.

    Why did this happen?

    Regards,
    Jesse

    #1607904
    David
    Staff
    Customer Support
    #1610780
    Jesse

    Thanks, David. That worked!

    #1611068
    David
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.