The get_search_form
function doesn’t work like that. The parameter that is accepted only specifies if the HTML
content is being returned or outputted directly. So this parameter should be a boolean. It still works in your case because PHP simply evaluates the string that you are passing as true considering that it is not an empty string, 0, null
etc. It would still work if you would pass ‘null’ as a string and not null
the keyword 🙂
In case you are not willing to write your own basic get_search_form
implementation (which is not difficult at all if you look in the source code – the locate_template
function does all the magic so just pass a variable to your function with the template name and use that when calling the locate_template
function) you can do something like setting a global variable right before calling the get_search_form
with what HTML you would like to use.
Then, when hooking to the get_search_form
filter, simply check what that global variable was set to and return the appropriate HTML
content. Internally WordPress uses a lot of global variables so you would just follow the broken, bad practice that it is already in place I suppose (in case you have a hard time using global variables).