Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Accessibility on Seach Modal

  • fgonzaleznavarro

    I need to add a label to the search form modal, so its compliant with accessibility rules

    this is the code that currently the theme spits out which has a label but its not linked to the seachfield:

    <div class=”gp-modal gp-search-modal gp-modal–open” id=”gp-search”>
    <div class=”gp-modal__overlay” tabindex=”-1″ data-gpmodal-close=””>
    <div class=”gp-modal__container”>
    <form role=”search” method=”get” class=”search-modal-form” action=”https://perkinsglobalcommunity.org/lac/staging/4478/”&gt;
    <label class=”screen-reader-text”>Buscar:</label>
    <div class=”search-modal-fields”>
    <input type=”search” class=”search-field” placeholder=”Buscar…” value=”” name=”s”>
    <button aria-label=”Buscar”><span class=”gp-icon icon-search”><svg viewBox=”0 0 512 512″ aria-hidden=”true” xmlns=”http://www.w3.org/2000/svg&#8221; width=”1em” height=”1em”><path fill-rule=”evenodd” clip-rule=”evenodd” d=”M208 48c-88.366 0-160 71.634-160 160s71.634 160 160 160 160-71.634 160-160S296.366 48 208 48zM0 208C0 93.125 93.125 0 208 0s208 93.125 208 208c0 48.741-16.765 93.566-44.843 129.024l133.826 134.018c9.366 9.379 9.355 24.575-.025 33.941-9.379 9.366-24.575 9.355-33.941-.025L337.238 370.987C301.747 399.167 256.839 416 208 416 93.125 416 0 322.875 0 208z”></path></svg></span></button>
    </div>
    </form>
    </div>
    </div>
    </div>

  • Do you want to add aria-label to the search field? if so, try this PHP code, I’ve added this line:
    aria-label="search-fields", so locate this line and change it to whatever you want to use for the aria-label.

    add_action ('wp', function() {
    	remove_action( 'generate_inside_search_modal', 'generate_do_search_fields' );
    });
    
    add_action( 'generate_inside_search_modal', 'generate_custom_do_search_fields' );
    
    function generate_custom_do_search_fields() {
    	?>
    	<form role="search" method="get" class="search-modal-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    		<label class="screen-reader-text"><?php echo apply_filters( 'generate_search_label', _x( 'Search for:', 'label', 'generatepress' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></label>
    		<div class="search-modal-fields" aria-label="search-fields">
    			<input type="search" class="search-field" placeholder="<?php echo esc_attr( apply_filters( 'generate_search_placeholder', _x( 'Search &hellip;', 'placeholder', 'generatepress' ) ) ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
    			<button aria-label="<?php echo esc_attr( apply_filters( 'generate_search_button', _x( 'Search', 'submit button', 'generatepress' ) ) ); ?>"><?php echo generate_get_svg_icon( 'search' ); // phpcs:ignore -- Escaped in function. ?></button>
    		</div>
    		<?php do_action( 'generate_inside_search_modal_form' ); ?>
    	</form>
    	<?php }
  • fgonzaleznavarro

    That worked, thank you.

  • You are welcome   🙂

  • I think this is what I’m looking for today, but can this code be included in Elements to keep everything simple and from having to edit the Functions theme file?

    To be clear, this will add a label to the search modal on the menu bar without affecting the functionality of the modal when activated?

  • You can use one of the methods to add this code:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    It can NOT be added to an element.

    To be clear, this will add a label to the search modal on the menu bar without affecting the functionality of the modal when activated?

    Correct. But please note, it only modifies the default GP search modal, if you are using a custom one, it will not work.

  • Yeah, I am looking to add the label to our custom modal.

  • This is what we want:
    search
    search mobile

  • If you are saying adding a <label> to the form html or adding the aria-label attribute to the form, we can not help with that, you would need to reach out to the custom form provider.

    If you mean to add search text in front of the search icon, we can help!

    But can you open a new topic and link us to your site?

  • Ahh, it’s actually the latter. My bad, will do – thanks!

  • No problem 🙂

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