• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Custom search form

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Custom search form

This topic is: not resolved

Tagged: custom search form, generate

  • This topic has 2 replies, 2 voices, and was last updated 9 years, 4 months ago by [email protected].
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • October 30, 2013 at 8:36 am #69893
    [email protected]
    Member

    Using: Genesis with Generate Child Theme
    Site: On local server

    Hi, I'm trying to do something really simple but I'm pretty sure I'm
    doing it completely wrong. Basically, all I really need to do is add
    some custom html. I'm calling the form in my theme with <?php get_search_form(); ?>

    To modify the search form, I've added the code below to functions.php.

    As you can see, I've actually unset the genesis_search_form and
    basically just copied the genesis_search_form code in to my own
    function and made some changes (This is totally hacky).

    I think I should be creating a custom search form and calling it in my theme
    differently but I'm not sure how. I've done this sort of thing in a
    couple of other cases too so I think if I can do this correctly I will be on a roll. Thanks!

    //Custom search form
    remove_filter( 'get_search_form', 'genesis_search_form' );
    add_filter( 'get_search_form', 'uthsc_search_form' );
    function uthsc_search_form() {
    	$search_text = get_search_query() ? apply_filters( 'the_search_query', get_search_query() ) : apply_filters( 'genesis_search_text', __( 'Search ', 'genesis' ) . '…' );
    
    	$button_text = apply_filters( 'genesis_search_button_text', esc_attr__( '', 'genesis' ) );
    
    	$onfocus = "if ('" . esc_js( $search_text ) . "' === this.value) {this.value = '';}";
    	$onblur  = "if ('' === this.value) {this.value = '" . esc_js( $search_text ) . "';}";
    
    	//* Empty label, by default. Filterable.
    	$label = apply_filters( 'genesis_search_form_label', '' );
    
    	if ( genesis_html5() )
    		$form = sprintf( '
    		<form method="get" class="search-form" action="%s" role="search">%s
    			<input type="search" name="s" placeholder="%s" />
    			<input type="submit" value="%s" />
    		</form>', 
    		home_url( '/' ), esc_html( $label ), esc_attr( $search_text ), esc_attr( $button_text ) );
    	else
    		$form = sprintf( '
    		<form method="get" class="searchform search-form" action="%s" role="search" >%s
    			<input type="text" value="%s" name="s" class="s search-input" onfocus="%s" onblur="%s" />
    			<input type="submit" class="uthsc-header-search searchsubmit search-submit" value="" />
    		</form>', 
    		home_url( '/' ), esc_html( $label ), esc_attr( $search_text ), esc_attr( $onfocus ), esc_attr( $onblur ), esc_attr( $button_text ) );
    
    	return apply_filters( 'genesis_search_form', $form, $search_text, $button_text, $label );
    }
    http://localhost
    November 17, 2013 at 1:42 pm #73703
    Robert Neu
    Member

    It looks like all you're doing is changing the class of the submit button, but I could be missing something.

    If that's all you're doing, you probably can achieve what you're trying to do another way, such as targeting the selector surrounding the form itself.

    If you're set on doing it this way but without unhooking and rehooking the entire search form, you would want to write a filter targeting genesis_search_form and return a new version of $form.

    It would be easier to give you a good course of action if we could see the site you're working on...


    Co-Founder of Audit WP, a WordPress SEO audit service and Flagship, a new WordPress theme company launching soon!

    November 18, 2013 at 9:41 am #73943
    [email protected]
    Member

    Hey, Thanks for the response.

    The site is under development with a private IP so I can't share it. However, I'm the answer I'm looking for shouldn't be site specific. I was just having some trouble finding documentation about the proper way to create custom search forms. I'm sure this is something genesis makes easy. Any tips or links?

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble