Show a message instead of redirect
-
Hi ! I have this code. It makes to be redirected to homepage when you try to search something shorter than 3 letters. I want to show a message “your search should be longer than 3 letters” instead of redirect to homepage
$query = get_search_query();
// if the first & last char is space, rip them
$query = trim($query);
// if there are more than one space, rip to one space
$query = preg_replace(‘/ss+/’, ‘ ‘,$query);
// if chars count is less than 3, redirect them to homepage
if (strlen($query)<3){
wp_redirect( home_url() );
exit;
} -
Hi there,
On what site are you working? The account you’re using to post here does not own any sites on WordPress.com.
If you’re using the open source WordPress software at another host, please ask for help at https://wordpress.org/support/forums instead.
- The topic ‘Show a message instead of redirect’ is closed to new replies.