Genesis – Customize search form

I’m not sure why you’re getting a 500 error. Likely because you’re trying to use a function before it’s been defined.

But I think you’re going about the problem the wrong way. Genesis does provide a filter before returning the search form. Why not just add a filter to the genesis_search_form hook?

You can add the filter to your child theme functions.php file:

add_filter( 'genesis_search_form', function( $form, $search_text, $button_text, $label ) { 
  return str_replace( 
    'type="search"', 
    'type="search" autocomplete="off" spellcheck="false" autocorrect="off" autocapitalize="off" dir="auto"', 
    $form 
  );
}, 10, 4 );

Alternate (untested, but it should work) method using substr_replace():

add_filter( 'genesis_search_form', function( $form, $search_text, $button_text, $label ) { 
  $insert=" autocomplete="off" spellcheck="false" autocorrect="off" autocapitalize="off" dir="auto"";
  $needle="type="search"";
  $where = strpos( $form, $needle ) + strlen( $needle );
  return substr_replace( $form, $insert, $where, 0 );
}, 10, 4 );

You’re getting a 500 error because you can’t have a function as an argument in sprintf(). Try this:

//* Add the search bar
add_filter( 'wp_nav_menu_items', 'sp_menu_items', 10, 2 );
function sp_menu_items( $items, $args ) {
    $form = get_search_form( false );
    $items .= sprintf( '<li id="sb" class="menu-item sb">%s</li>', $form );
    return $items;

}

Leave a Comment