Created
April 1, 2014 17:01
-
-
Save sglessard/9918363 to your computer and use it in GitHub Desktop.
Wordpress custom rewrite example
This file contains hidden or 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
| /** | |
| * 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