How To Redirect To Post If Search Results Return One Post In WordPress

WordPress’s built-in search function allow you and your visitors to easily search posts on your WordPress site by typing the keyword. Here’s a trick which will redirect to post if search results return one post. Why waste user’s time if his term only matches in the one post in your blog. This trick will directly take him to the post, instead of showing the search page with only a single result.

Add following snippet to your current theme’s functions.php file to check if the search result only has one post, if it has then it performs a redirection to the post: