Last active
November 10, 2016 19:11
-
-
Save joedajigalo/1ec88f26d0515f6d8120 to your computer and use it in GitHub Desktop.
Add a Search shortcode to WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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