Skip to content

Instantly share code, notes, and snippets.

@andreiglingeanu
Created March 27, 2023 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andreiglingeanu/374d4ea4be7be484ff67f09acdf57c16 to your computer and use it in GitHub Desktop.
Save andreiglingeanu/374d4ea4be7be484ff67f09acdf57c16 to your computer and use it in GitHub Desktop.
<?php
add_action('template_redirect', function () {
if (is_search() && isset($_GET['s'])) {
$current_url = wp_parse_str(wp_parse_url(blocksy_current_url())['query'], $query_args);
unset($query_args['s']);
wp_redirect(add_query_arg(
$query_args,
home_url("/search/") . urlencode(get_query_var('s'))
));
exit();
}
});
add_action('init', function () {
add_rewrite_rule(
'^search\/([^/]*)\/?',
'index.php?s=$matches[1]',
'top'
);
}, 10, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment