Skip to content

Instantly share code, notes, and snippets.

@joedajigalo
Last active November 10, 2016 19:11
Show Gist options
  • Save joedajigalo/1ec88f26d0515f6d8120 to your computer and use it in GitHub Desktop.
Save joedajigalo/1ec88f26d0515f6d8120 to your computer and use it in GitHub Desktop.
Add a Search shortcode to WordPress
<?php
/* Wordpress Search Form - Shortcode
-------------------------------------------------- */
/*
* USAGE:
* Post Content: [shortcode_search]
* Template: echo do_shortcode("[shortcode]");
*/
function shortcode_search_form( $form ) {
$form = '
<form class="form-inline" role="search" method="get" action="' . home_url( '/' ) . '">
<div class="form-group">
<label class="sr-only" for="s">Search</label>
<input type="text" class="form-control" id="s" name="s" placeholder="Search..." value="' . get_search_query() . '">
</div>
<button type="submit" class="btn btn-primary">Search</button>
</form>
';
return $form;
}
add_shortcode('shortcode_search', 'shortcode_search_form');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment