Question

I want to make a search button that search only within my website.

  1. Do I need external PHP or PERL script?
  2. Can it done by JavaScript?
  3. Or simply by HTML.

I tried to create a form using HTML:

<form>
    <input type="search" name="banner_search" class="banner-text-box" >
    <input type="submit" name="" value="SEARCH" class="banner-text-btn">
</form>
Était-ce utile?

La solution

You can use WordPress's internal search by calling the get_search_form() function:

<?php get_search_form(); ?>

get_search_form() will use a default HTML form, but you can create your own custom form by adding a searchform.php file to your theme.

Autres conseils

You can add this HTML form to your page

<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <div>
        <label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
        <input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" class="banner-text-box" />
        <input type="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" class="banner-text-btn"/>
    </div>
</form>

Refrence:

Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top