How to display search form in WordPress theme

Posted in: WordPress , Comments Off

You can use below php code to display search form in a WordPress theme:

<?php get_search_form(); ?>

This will show WordPress inbuilt search form. If you want to display custom search form, follow below steps:

Step 1:

Create a file searchform.php in your theme directory.

Step 2:

Add your custom search box code in searchform.php

Example of custom search form code:

<form action="/" method="get">
        <label for="search">Search in <?php echo home_url( '/' ); ?></label>
        <input type="text" name="s" id="search" value="<?php the_search_query(); ?>" />
        <input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" />

Step 3:

Use below code to display this search form in your theme:

<?php get_search_form(); ?>

About the Author

Name: Ravi Shekhar
I love learning and sharing web stuffs.

Share this post

Twitter Facebook Google Buzz Digg StumbleUpon Delicious Technorati
Both comments and pings are currently closed.

Comments are closed.