Add a Search field anywhere in a Drupal template file

When I’m theming a site in Drupal, I don’t always use the search block that Drupal provides. Sometimes I like to put a search field in the header, sidebar, or even in the off-canvas menu. This snippet will let you display a search field anywhere you’d like.

<div id="search-form" class="search">
    <?php $form = drupal_get_form('search_block_form', TRUE); ?>
    <?php print render($form); ?>
</div>