Created
June 29, 2022 14:54
-
-
Save jshwlkr/17a3520f54f0b97ce540b7deb02c8807 to your computer and use it in GitHub Desktop.
Redirect WordPress' native search to an external engine, like Google's Programmable Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function redirect_search() { | |
if (is_search() && !empty($_GET['s'])) { | |
wp_redirect('https://cse.google.com/cse?cx=PSE_ID&q=' . urlencode(get_query_var('s')) ); | |
exit(); | |
} | |
} | |
add_action('template_redirect', 'redirect_search' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment