[wp-hackers] Search form issue

Will Anderson will at itsananderson.com
Tue Sep 6 01:42:54 UTC 2011

If you REALLY need to do custom markup for each form (though I'd agree with
Otto. It's probably not necessary), and if you want to use get_search_form,
you could utilize the get_search_form hook in get_search_form with something
like the following and create an empty searchform.php so the default search
form isn't output:

function header_search_form() {
add_action( 'get_search_form', 'show_header_search_form');
remove_action('get_search_form', 'show_header_search_form');

function show_header_search_form() {
// header search form code

function sidebar_search_form() {
add_action('get_search_form', 'show_sidebar_search_form');
remove_action('get_search_form', 'show_sidebar_search_form');

function show_sidebar_search_form() {
// sidebar search form code

TL;DR - Use some CSS!


P.S you *could* also use global variables, eg "global $header_search;
$header_search = true; get_search_form(); $header_search = false;" and then
check those in searchform.php, but that's just as clunky as (if not more
clunky than) the other option. Again, CSS is probably the best option.

On Mon, Sep 5, 2011 at 9:28 PM, Otto <otto at ottodestruct.com> wrote:

> On Mon, Sep 5, 2011 at 7:44 PM, Daniel Fenn <danielx386 at gmail.com> wrote:
> >>> I am currently working on a new version of my wordpress theme, and I am
> >>> running into a serious issue. The theme guideline says that I must use
> >>> "get_search_form();" to display the search form. Now I am running into
> an
> >>> issue where the form will need different markup for the header, sidebar
> >>> and
> >>> search result page. (No I am not kidding).
> What exactly is different about the HTML markup between these two? It
> seems to me that just about anything you want to do to change a search
> form around could be accomplished with CSS adjustments.
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list