Skip to content

Instantly share code, notes, and snippets.

@sglessard
Created April 1, 2014 17:01
Show Gist options
  • Save sglessard/9918363 to your computer and use it in GitHub Desktop.
Save sglessard/9918363 to your computer and use it in GitHub Desktop.
Wordpress custom rewrite example
/**
* Custom rewrite rule
* 1) conseils-pratiques/trucs-et-astuces clienteles
*
* Note: using page_id param seems important (no luck with pagename param)
*
* @param $wp_rewrite
*/
function kw_custom_rewrite( $wp_rewrite ) {
$feed_rules = array(
'^page-slug/sub-page-slug/([^/]+)/?' => 'index.php?page_id=15&some_new_parameter=' . $wp_rewrite->preg_index(1),
);
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}
function kw_custom_wp_querystring() {
add_rewrite_tag('%some_new_parameter%','([^&]+)');
}
add_filter( 'generate_rewrite_rules', 'kw_custom_rewrite' );
add_action( 'init', 'kw_custom_wp_querystring');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment