I'm currently building a custom WordPress template and I've run into a problem with the search box.
When I use the searchbox from the homepage, it works as intended. It also works as long as Permalinks are set to default. (url/?page_id=1
)
However, when I use the searchbox from another page when using pretty permalinks, the URL looks something like this:
/?s=query
and a 404 page appears.
My search box code looks like this
<form id="search-query">
<div class="search-box">
<form role="search" method="get" id="searchform" class="searchform" action="/index.php">
<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" />
<input type="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
</form>
</div>
</form>
Here's the site's URL if anyone's want to take a look: /
Any help is very appreciated!
I'm currently building a custom WordPress template and I've run into a problem with the search box.
When I use the searchbox from the homepage, it works as intended. It also works as long as Permalinks are set to default. (url/?page_id=1
)
However, when I use the searchbox from another page when using pretty permalinks, the URL looks something like this:
http://url/pretty-page-title/?s=query
and a 404 page appears.
My search box code looks like this
<form id="search-query">
<div class="search-box">
<form role="search" method="get" id="searchform" class="searchform" action="/index.php">
<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" />
<input type="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
</form>
</div>
</form>
Here's the site's URL if anyone's want to take a look: http://hermodsgymnasiet-develop.kaigan.modxcloud/
Any help is very appreciated!
Share Improve this question asked Nov 25, 2015 at 15:36 ErikaErika 1071 silver badge6 bronze badges 1 |2 Answers
Reset to default 0Currently your form looks like:
<form id="search-query">
<p class="in-english"><a href="http://localhost/hermodswp/?page_id=76">Information in English</a></p>
<div class="search-box">
<div>
<label class="screen-reader-text" for="s"></label>
<input type="text" value="sdf" name="s" id="s" style="width: 293px;">
<input type="submit" id="searchsubmit" value="Sök">
</div>
</div>
</form>
Try adjusting your submit action to point to your home_url().
action="<?php echo home_url(); ?>"
You can edit the page in Chrome to see that this works fine.
<form role="search" id="search-query" method="get" action="http://hermodsgymnasiet-develop.kaigan.modxcloud/">
<p class="in-english"><a href="http://localhost/hermodswp/?page_id=76">Information in English</a></p>
<div class="search-box">
<div>
<label class="screen-reader-text" for="s"></label>
<input type="text" value="" name="s" id="s" style="width: 293px;">
<input type="submit" id="searchsubmit" value="Sök">
</div>
</div>
</form>
Simply add action="/"
to your form!
http://url/pretty-page-title/?s=query
with a bundled theme-- one of the "Twenty {Something}" ones. – s_ha_dum Commented Nov 25, 2015 at 15:55