Community Forums › Forums › Archived Forums › General Discussion › Custom search form
Tagged: custom search form, generate
- This topic has 2 replies, 2 voices, and was last updated 11 years, 2 months ago by [email protected].
-
AuthorPosts
-
October 30, 2013 at 8:36 am #69893[email protected]Member
Using: Genesis with Generate Child Theme
Site: On local serverHi, 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!
http://localhost//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 ); }
November 17, 2013 at 1:42 pm #73703Robert NeuMemberIt 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...
November 18, 2013 at 9:41 am #73943[email protected]MemberHey, 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?
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.