Created
January 28, 2021 04:01
-
-
Save thecodepoetry/fd5b08cff491967a8884f30353747bc4 to your computer and use it in GitHub Desktop.
Custom search for shortcode only for post
This file contains 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
function cpsearchform( $form ) { | |
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" > | |
<div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label> | |
<input type="text" value="' . get_search_query() . '" name="s" id="s" /> | |
<input type="hidden" name="post_type" value="post" /> | |
<input type="submit" id="searchsubmit" class="dt-btn" value="'. esc_attr__('Search') .'" /> | |
</div> | |
</form>'; | |
return $form; | |
} | |
add_shortcode('cpsearch', 'cpsearchform'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add the code in your child theme functions.php to create a custom search form only for posts and then use the shortcode [cpsearch] to display the form