Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
Forked from andreiglingeanu/test.php
Last active March 28, 2023 09:05
Show Gist options
  • Save tdmrhn/179debb4b8fc01372fee704d5cb0a8d8 to your computer and use it in GitHub Desktop.
Save tdmrhn/179debb4b8fc01372fee704d5cb0a8d8 to your computer and use it in GitHub Desktop.
Change search slug add rewrite rule
<?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