The easiest way:
- create a page template that only includes the search form (
get_search_form()
) - create a page and assing the template
- In the
href
attrib of the iframe, instead of put the url forsearchform.php
put the url of the page
Pretty easy, but you need a query to get the page. A more performant way is to use fancybox without iframe, but via ajax, e. g.:
<?php
$url = add_query_arg( array('action'=>'show_search_form'), admin_url('admin-ajax.php') );
?>
<a id="search-label" href="https://wordpress.stackexchange.com/questions/153098/<?php echo $url; ?>"></a>
Then use ajax API to call get_search_form()
inside the ajax action, e. g.:
add_action( 'wp_ajax_show_search_form', 'mytheme_show_search_form' );
add_action( 'wp_ajax_nopriv_show_search_form', 'mytheme_show_search_form' );
function mytheme_show_search_form() {
get_search_form();
exit();
}