Auto-Redirect when WordPress Search Query Only Returns One Match

There are times when searching a WordPress blog, you only get one item in the result. Depending on how organized your site is, this should be the item the user was looking for anyways. One of our users asked if there was a way to redirect to the post if the search query results only one match. In this article, we are going to show you how to redirect users to the post when the search query only returns one match.

All you have to do is open your theme’s functions.php file and paste the following snippet.

Tables can't be imported directly. Please insert an image of your table which can be found here.

1 2 3 4 5 6 7 8 9

Now you must beware that some users will not expect this functionality. So it may freak them out.

Was this article helpful?
0 out of 0 found this helpful