Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Go straight to the only search result

When a search finds exactly one post, the visitor goes straight to it instead of a results page with one link.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Search and archives
  • Tested with WordPress 7.1
PHP
<?php

add_action(
	'template_redirect',
	static function () {
		global $wp_query;
		if ( is_search() && ! is_paged() && 1 === (int) $wp_query->found_posts && ! empty( $wp_query->posts[0] ) ) {
			wp_safe_redirect( get_permalink( $wp_query->posts[0] ) );
			exit;
		}
	}
);

In these packs

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.