How to add a Custom Search Form in your Post in WordPress


How to add a Custom Search Form in your Post in WordPress

Adding a search form in your website is a good idea and it helps visitors to find out the required content easily from your site.

In WordPress there are many ways you can add search form in your post or page.

Here we will discuss mainly 3 methods to achieve it.

 

  1. WordPress inbuilt function.
  2. Creating a Shortcode to add search form
  3. Adding Search form using custom form codes

Method 1: WordPress inbuilt function

For adding a default search form in your post or custom theme you can use a very simple function of WordPress to add search form and it is  <?php get_search_form(); ?> .

Add it in your page template and after adding this function you will see a default search form in your post/page.

It need some basic knowledge of html, need to add it in post/page template.

 

Method 2: Creating a Shortcode to add search form

For creating a shortcode for search form , just add these codes in function file of your active theme.

function yuvisearchform( $form ) {

$form = '<form role="search" method="get" id="yusearchform" action="' . home_url( '/' ) . '" >
<div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
<input type="text" value="' . get_search_query() . '" name="s"/>
<input type="submit" id="yusearchsubmit" value="'. esc_attr__('Search') .'" />
</div>
</form>';

return $form;

}
add_shortcode('yuvisearch', 'yuvisearchform');

 

after adding these forms you can use shortcode [yuvisearch] to add search form.

 

Method 3: Adding Search form using custom form codes

Add these html codes in your theme where you want to add this search form

<form class="input-group p-0 .d-none .d-lg-block col-12 my-2" role="search" method="get" action="<?php echo home_url( '/' ) ?>" >
<input type="text" class="form-control py-4" placeholder="Search" value="<?php echo get_search_query();?>" name="s">
<div class="input-group-append">
<button type="submit" class="btn btn-warning" type="button">Search</button>
</div>
</form>

 

These codes will create a very nice search form to use.

 

Hope this will help to add a search form in your WordPress website.

Share on: Share YogiRaj B.Ed Study Notes on twitter Share YogiRaj B.Ed Study Notes on facebook Share YogiRaj B.Ed Study Notes on WhatsApp
Insight Learning – Wolfgang Kohler: Theory and Definition
Q. Insight Learning – Wolfgang Kohler: Theory And Definition

Insight learning is a theory of learning first put forth by Wolfgang Kohler about 90 years ago.
Theory development
In the 1920s, German psychologist Wolfgang Kohler was studying the behavior of apes. He designed some simple experiments that led to the development of one of the first cognitive theories of learning, which he called insight learning.
In his experiment, Kohler hung a piece of fruit just out of reach of each chimp

Read full article
B.F Skinners – Operant Conditioning
Q. B.F Skinners – Operant Conditioning

What Is Operant Conditioning?
Operant conditioning (sometimes referred to as instrumental conditioning) is a method of learning that occurs through rewards and punishments for behavior. Through operant conditioning, an association is made between a behavior and a consequence for that behavior.

Read full article
What Is Dual Coding Theory

Dual-coding theory, a theory of cognition, was hypothesized by Allan Paivio of the University of Western Ontario in 1971. In developing this theory, Paivio used the idea that the formation of mental images aids in learning.
According to Pavio –
”Human cognition is unique in that it has become specialized for dealing simultaneously with language and with nonverbal objects and events.”

Read full article
Practical Meaning and Educational Applications of Dual Coding Theory
Q. What is the practical meaning of dual coding theory?

Dual coding theory suggests that combining verbal and graphical material in learning (or just encouraging students to generate appropriate mental images) should increase the probability that words will activate corresponding images and vice-versa.
This also means that learning material will be easier to relate if it is less abstract.

Read full article

Some important study notes