the search.php is the search page template for WordPress, in this search template development we will learn to make a search form and search result displaying page so first, we will make a search form in any position of the theme
The search form code for WordPress search function
Here the form action will be the homepage location of the theme and for that using the code and the name of the text type input as “s” and the method of submission of the page must be getting as the URL after submission should show https://your-site-domain.com?s=search+key
Now Start to make the archive page step by step
Step 1
make a search.php file inside your WordPress custom theme folder
Step 2
get an HTML template to show the search result loop and copy the HTML code and paste it into your search.php file.
Step 3
Now place the custom theme header, footer, and sidebar in its position using the code ,
, and
Step 4
Make the search page title dynamic using the code ' . get_search_query() . '' ); ?>
Step 5
In search.php file, WordPress is used to send only the post loop related to the searched keyword inside content or title now write the below code to get the search result loop
Step 6
Now reset the wp-query using the code
Step 7
Now here is the full code to make a custom search page template
now test the search result page and its ready for use to show the searched post in your WordPress theme