ellewhin
Member
Posted 11 months ago #
Hello,
I would like my search form to return results in a normal manner except when one specific search term is entered I would like to direct the user to a specific url.
Basically, when a user searches for the title of the blog I would like for them to be sent to the front page of the blog.
How can I go about doing this?
Thanks
in the very top of your themes header.php you can add:
<?php
if(is_search()) {
if(preg_match('/\byoursitename\b/i', get_search_query()) == TRUE){
wp_redirect(home_url());
exit;
}
}
?>
change 'yoursitename' to your site's well, name.
http://www.php.net/manual/en/function.preg-match.php
ellewhin
Member
Posted 11 months ago #
Hi tugbucket,
Thanks for your reply!
When I insert the code you provided and try a search for my site's name I get the following error:
Warning: Cannot modify header information - headers already sent by (output started at /blahurlblahblah/header.php:2) in /blahblahblahurl/wp-includes/pluggable.php on line 897
Any ideas?
Where did you put the code? It needs to be the very first thing in your theme's header.php.
ellewhin
Member
Posted 11 months ago #