Users always use the search the keywords in wordpress sites. Many times clients wish about this functionality. If there is only one result came from search result than user should redirect to single landing post.

Search result is single than redirect to wordpress post

If there is Search result is single then redirect to wordpress should redirect to single landing post.

You should open the functions.php file and  put following code in functions.php file.

<pre>add_action('template_redirect', 'redirect_single_post');
function redirect_single_post() {
    if (is_search()) {
        global $wp_query;
        if ($wp_query->post_count == 1) {
            wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
        }
    }
}
Search result is single than redirect to wordpress post

Search result is single than redirect to wordpress post

Written by Purab

My name is Purab, Here is my Personal Blog: wpapi.com. I contributor of many wordpress plugins and Drupal Modules. I am core developer of Drupal. Connect to on LinkedIn or Follow @purab on Twitter or Follow me on Google+ or Write Mail to purabdk@gmail.com or Chat with me on Skype : purabdk

Leave a Comment

Your email address will not be published. Required fields are marked *