Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add one or more classes to the WordPress search form's 'Search' button
<?php
/**
* Add one or more classes to the WordPress search form's 'Search' button
* @author Alain Schlesser (alain.schlesser@gmail.com)
* @link http://www.brightnucleus.com/add-class-wordpress-search-button/
*
* @param string $form the search form HTML output
* @return string modified version of the search form HTML output
*
* @see http://codex.wordpress.org/Function_Reference/get_search_form
* @see http://developer.wordpress.org/reference/hooks/get_search_form/
*/
function as_adapt_search_form( $form ) {
// $forms contains the rendered HTML output of the standard search form
// the exact output is changed if your theme has declared HTML5 support
// with the following minimum settings:
//
// add_theme_support( 'html5', array( 'search-form' ) );
//
// see http://codex.wordpress.org/Function_Reference/add_theme_support
// add Foundation classes to the button class
//
// we do a string replace and search for 'search-submit', which is the one
// class that is already defined for the HTML5 search form
//
// if HTML5 search-form support has not been defined, this will leave the
// HTML output unchanged
$form = str_replace(
'search-submit',
'search-submit small radius button',
$form
);
// return the modified string
return $form;
}
// run the search form HTML output through the newly defined filter
add_filter( 'get_search_form', 'as_adapt_search_form' );
?>
@schlessera

This comment has been minimized.

Copy link
Owner Author

commented Jan 10, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.