简体   繁体   中英

Redirect search to home page

I have a custom search bar which works fine on my Wordpress home page, however when I place it on a different page of the site, the URL keeps directing to http://localhost/pageName/?s=searchTerm instead of http://localhost/?s=searchTerm . I've tried setting form action to

<form method="get" id="searchform"  action="<?php echo esc_url( home_url( '/' ) ); ?>">

and also hardcoding my site URL but the redirect happens every time.

Here is my searchform.php file:

<form method="get" id="searchform"  action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div>
    <input type="text" value="<?php echo the_search_query(); ?>" name="s" id="s" placeholder="Search" />
</div>
</form>  

How would I get the form to direct to http://localhost/?s=searchTerm ?

写吧

<form method="get" id="searchform"  action="/">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM