custom search form wordpress – How to Create Custom Search Form in WordPress?

custom search form wordpress – Creating a custom search form in WordPress is super easy.

custom search form wordpress

Just simple way to create a new php file called searchform.php and save it on your published themes. just In this file add your markup of the search form. first of all Open your theme’s functions. here Create a Custom Search Form in WordPress.

Create a Custom Search Form

searchform.php

<form id="searchform" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <input type="text" class="search-field" name="s" placeholder="Search" value="<?php echo get_search_query(); ?>">
    <input type="submit" value="Search">
</form>

Display Search Form

<?php get_search_form(); ?>

Customize Search Result

<form id="searchform" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <input type="text" class="search-field" name="s" placeholder="Search" value="<?php echo get_search_query(); ?>">
    <input type="hidden" name="post_type[]" value="laravel" />
    <input type="hidden" name="post_type[]" value="php" />
    <input type="hidden" name="post_type[]" value="angularjs" />
    <input type="hidden" name="post_type[]" value="javascript" />
    <input type="submit" value="Search">
</form>

How to create a custom search form in WordPress?

<form role="search" method="get" class="searchform group" action="<?php echo home_url( '/' ); ?>">
 <label>
 <span class="offscreen"><?php echo _x( 'Search for:', 'label' ) ?></span>
 <input type="search" class="search-field"
 placeholder="<?php echo esc_attr_x( 'Search', 'placeholder' ) ?>"
 value="<?php echo get_search_query() ?>" name="s"
 title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
 </label>
 <input type="image" alt="Submit search query"
 src="<?php echo get_template_directory_uri(); ?>/images/search-icon.png">
</form>

Don’t Miss : Creating Custom Database Tables Plugin Or Theme Using WordPress

I hope you get an idea about custom search form wordpress.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.