WordPress resource site for WordPress Beginners with easy to understand WordPress tutorials for mastering the basics and beyond.

WordPress Guide

WordPress Guide

Step by step guide on how to add the WordPress search form in your post or page content by creating a WordPress search shortcode. Make your site searchable to increase visitor retention. We’ll show you how to use the WordPress search bar shortcode and place the search on your site. WP shortcode for default search form

How to Add Search Form in your Post with a WordPress Search Shortcode

add_shortcode(‘wpbsearch’, ‘get_search_form’);

use the shortcode in your post/page content like so: [wpbsearch]

How to Add a Search Bar to WordPress Using Shortcode

Copy and paste the following lines of code into the functions.php file.

function searchbar( $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=”submit” id=”searchsubmit” value=”‘. esc_attr__(‘Search’) .'” />

return $form;

add_shortcode(‘searchbar’, ‘searchbar’);