# Send Certain Searches Straight to a Page

> Opens a chosen page directly when someone searches for an exact word or phrase, for example "contact" goes to your contact page and "returns" to your returns policy.

- Type: PHP
- Runs: Run everywhere
- Category: [Search](https://wpide.com/library/category/search/)
- Tags: search, redirects, shortcuts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/search-keyword-redirects/

## Code

```php
// Search words => page to open instead of the results. Matching ignores upper/lower case. Empty = off. Examples:
// 'contact'  => '/contact/',
// 'opening hours' => '/visit/#hours',
$wpide_search_shortcuts = array();

add_action( 'template_redirect', function () use ( $wpide_search_shortcuts ) {
    if ( ! $wpide_search_shortcuts || ! is_search() || is_paged() ) {
        return;
    }

    $phrase = strtolower( trim( preg_replace( '/\s+/', ' ', (string) get_search_query( false ) ) ) );

    foreach ( $wpide_search_shortcuts as $words => $target ) {
        if ( strtolower( trim( $words ) ) === $phrase ) {
            wp_safe_redirect( preg_match( '#^https?://#i', $target ) ? $target : home_url( $target ), 302 );
            exit;
        }
    }
} );
```

## Notes

The list is empty by default; matching ignores capital letters and extra spaces, and only whole searches match.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Certain Searches Straight to a Page" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
