Skip to content

Instantly share code, notes, and snippets.

@rianrietveld
Created November 22, 2012 05:44
Show Gist options
  • Save rianrietveld/4129586 to your computer and use it in GitHub Desktop.
Save rianrietveld/4129586 to your computer and use it in GitHub Desktop.
WordPress Genesis searchform with label and hook for genesis_header_right
.prefix-hidden {
background-color: #fff;
border: 1px solid #000;
display: block;
font-size: 1em;
left: -1000em;
padding: 0.8em;
position: absolute;
z-index: 10;
}
.hidden:focus, .hidden:active {
top:1em;
left:1em;
z-index:1000;
color: #1E6891;
}
<php
/**
* WordPress Genesis Accessible searchform for the header
* Rian Rietveld - rrwd.nl
* Add this to the functions.php in your child theme for the Genesis Framework by StudioPress.
* This function replaces the search form with a more accessible one by adding a hidden label
*/
add_action ('genesis_header_right' , 'prefix_header_search_and_sitemap');
function prefix_header_search_and_sitemap() {
?>
<form method="get" class="searchform" action="<?php echo home_url('/')?>">
<label for="s" class="prefix-hidden">Search this site</label>.txt
<input type="text" value="Search this website …" name="s" class="s" onfocus="if (this.value == 'Search this website …') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search this website …';}">
<input type="submit" class="searchsubmit" value="Search">
</form>
<?php
}
?>
@joanlsoler
Copy link

Hello. This search form is HTML5 compliant? Thanks in advance. Joan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment