Quick answer
- When a WordPress search finds just one post, you can send visitors straight to it instead of showing a results page with one item.
- Add a short code snippet that runs on the template_redirect hook: if it’s a search with exactly one result, redirect to that post.
- Use a code snippet plugin like WPCode rather than editing theme files.
- Test it with a search term that matches only one post.
A search results page with a single result is an unnecessary extra click. Here’s how to skip it in WordPress.
How it works
WordPress runs the
template_redirect action before loading a page. A snippet can check is_search() and whether the main query found exactly one post ($wp_query->post_count == 1), then redirect with wp_safe_redirect() to that post’s permalink.Step 1: Install a snippet plugin
Install WPCode from WordPress.org. It keeps custom code safe when you change themes.
Step 2: Add the snippet
- Add a new PHP snippet.
- Hook a function to template_redirect.
- Inside it, check is_search() and that exactly one post was found.
- Redirect to get_permalink() of that post, then exit.
- Set the snippet to run on the front end only and activate it.
Step 3: Test
- Search for a term that matches one post: you should land on it.
- Search for a common term: you should see the results page.
When not to use it
If your search includes products and pages, check that redirecting fits your visitors’ expectations.
FAQs
It saves visitors a click.
A small snippet works; WPCode makes adding it safe.
No. Search result pages shouldn’t be indexed anyway.
Yes, for product searches through the standard WordPress search.
Deactivate the snippet.
A typo in PHP can. WPCode helps prevent errors, and you should test after adding it.









