Add the following to your theme functions.php file:
function search_jump_page() {
if(is_search()) {
global $wp_query;
if ($wp_query->post_count == 1) {
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
}
}
}
add_action('template_redirect', 'search_jump_page');
Source: WordPress搜索功能结果只有一个时直接跳转到结果文章页面
Was this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂