-
-
Save tdmrhn/179debb4b8fc01372fee704d5cb0a8d8 to your computer and use it in GitHub Desktop.
Change search slug add rewrite rule
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
<?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