admin管理员组文章数量:1334919
For example, my wordpress website is www.example
. If I type example/abcdef
or any other url that does not exist, it redirects to my custom 404 page without any issues.
However, when I search something, the url changes to www.example/?s=abcdef
and it shows wordpress's default 'Nothing Found' page. Is there a way I can redirect a wrong search's to my custom 404 page or can I change wordpress 'Nothing found' page?
Thanks
For example, my wordpress website is www.example
. If I type example/abcdef
or any other url that does not exist, it redirects to my custom 404 page without any issues.
However, when I search something, the url changes to www.example/?s=abcdef
and it shows wordpress's default 'Nothing Found' page. Is there a way I can redirect a wrong search's to my custom 404 page or can I change wordpress 'Nothing found' page?
Thanks
Share Improve this question edited Jan 13, 2018 at 22:32 Temani Afif 6835 silver badges13 bronze badges asked Jan 13, 2018 at 22:23 NobbleNobble 33 bronze badges 2- Do you want to disable example/?s=* completely having that query string hit your custom 404? – Liam Stewart Commented Jan 13, 2018 at 22:26
- Thanks for replying. I don't want to disable 'example/?s=*' completely if it screws up the website's search function. I am looking to change the page that shows up when the search doesn't get any results. If I can customize it and add some of my custom text and image to it that would be better. If not, can it redirect to the error 404 page? Thanks – Nobble Commented Jan 13, 2018 at 22:31
1 Answer
Reset to default 2A search shows the search template regardless of whether or not there are any results, which is either search.php
or index.php
if that template doesn't exist.
If you want to load an entirely different template, you can use the search_template
filter. Assuming your theme's 404 template is 404.php
:
function wpd_search_template( $template ) {
if( ! have_posts() ) {
$template = locate_template( array( '404.php' ) );
}
return $template;
}
add_filter( 'search_template', 'wpd_search_template' );
本文标签: How to redirect a wrong search on my wordpress website to the error 404 page
版权声明:本文标题:How to redirect a wrong search on my wordpress website to the error 404 page? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742324918a2453531.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论