and like us on FB

If you searched this website for “Jennifer L.awrence” (prior to this post), the search would have redirected you to the only page on this site that contains that text (“Determine A Person’s Age From DOB“). It’s a fairly specific search term and, given that there’s only one result, it’s pretty clear what the user is looking for. In such instances, what’s the point of generating a “list” of search results? The following code will detect a single search result and redirect the user to the only post or page that matched your search criteria. It’s arguably a better user experience and likely to convert a little better than the alternative.

WordPress Code

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

You can download the code as a function for your custom functions file (labeled as shortcode) or as a plugin below.

Download

Title: Redirect WordPress Search To A Post If It Only Returns One Post
Description: The function will redirect a WordPress search result to a post or page if one one result is returned.
Download: Shortcode (V0.2) | WP Plugin (V0.2) | | Plugin Page

Shortt URL for this post: http://shor.tt/1PsE