Skip to content

Instantly share code, notes, and snippets.

@sourovroy
Created February 14, 2018 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sourovroy/ab469895f102e8ac6d6dda531c553e61 to your computer and use it in GitHub Desktop.
Save sourovroy/ab469895f102e8ac6d6dda531c553e61 to your computer and use it in GitHub Desktop.
WordPress allow any page to add extra url with it
<?php
/**
* Custom rewrite rule for career page
*/
add_action('init', function(){
add_rewrite_tag('%office_location%','([^&]+)');
add_rewrite_tag('%job_position%','([^&]+)');
});
add_filter( 'generate_rewrite_rules', function($wp_rewrite){
$feed_rules = array(
'careers/(.+)/(.+)' => 'index.php?page_id=62&office_location=' . $wp_rewrite->preg_index(1) . '&job_position='.$wp_rewrite->preg_index(2),
);
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment