WordPress

WordPress Shortcode Display Search Form

Spread the love

How to Add a WordPress Search Form by Shortcode

WordPress shortcode for default search form – The bellow code add in function.php

function shapeSpace_display_search_form() {
	return get_search_form(false);
}
add_shortcode('display_search_form', 'shapeSpace_display_search_form');

/* Bellow code is a  shortcode  */
[display_search_form]

WP shortcode for custom search form – The bellow code add in function.php

function shapeSpace_display_search_form() {
	$search_form = '<form method="get" id="search-form-alt" action="'. esc_url(home_url('/')) .'">
		<input type="text" name="s" id="s" placeholder="Search..">
	</form>';
	return $search_form;
}
add_shortcode('display_search_form', 'shapeSpace_display_search_form');

/* Bellow code is a  shortcode  */
[display_search_form]

WordPress Shortcode Display Search Form

Leave a Reply

Your email address will not be published. Required fields are marked *