Skip to content

Instantly share code, notes, and snippets.

@BAHC
Created May 31, 2019 02:15
Show Gist options
  • Save BAHC/7d247a189478a4f705d09cf0effe5925 to your computer and use it in GitHub Desktop.
Save BAHC/7d247a189478a4f705d09cf0effe5925 to your computer and use it in GitHub Desktop.
Custom routes in WP theme
<?php
//file /wp-content/themes/current-theme/functions.php
function custom_addRoutes() {
add_rewrite_rule('^([A-Za-z]+)/([A-Za-z\+]+)/([0-9]+)/?$', 'tour/?id=$matches[3]&city=$matches[2]&country=$matches[1]', 'top');
add_rewrite_rule('^([A-Za-z]+)/([A-Za-z\+]+)/?$', 'city/?city_name_en=$matches[2]&country=$matches[1]', 'top');
add_rewrite_rule('^([A-Za-z^index]+)/?$', 'country/?country_name_en=$matches[1]', 'top');
}
add_action('init', 'custom_addRoutes');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment