Craig Simpson

Web developer from Moray, Scotland

Showing the Genesis Search Form Label.

21st August 2015

No Comments

The upcoming release of Genesis 2.2 will bring a host of accessibility enhancements. I won’t go through them all, because Rian has already given us this fantastic run-through, but suffice to say these upgrades are being welcomed by one and all.

In a recent project, built with Genesis 2.2-RC1, I had the requirement to use a search form with the label visible and styled in a specific way. With support for accessible search forms enabled, the label is hidden as screen reader text.

I could have used CSS to force the screen reader text to show, but this would be more of a hack than a solution. I went in search of a way to remove the .screen-reader-text class from the search form markup.

Eventually a solution presented itself, with a little help from Gary.

1add_filter( 'genesis_search_form', 'prefix_unhide_search_label' );
2/**
3 * Remove the screen reader text class from the search form label.
4 *
5 * @param $markup
6 *
7 * @return string
8 */
9function prefix_unhide_search_label( $markup ) {
10 return str_replace( ' screen-reader-text', '', $markup );
11}

Adding this snippet to functions.php will filter the search form markup, and uses the PHP function str_replace to remove occurrences of .screen-reader-text.

Leave a Reply

Your email address will not be published. Required fields are marked *