SHOW:
|
|
- or go back to the newest paste.
| 1 | - | <?php // quick WordPress custom URL variables for /en/page-name & /fr/page-name |
| 1 | + | <?php // quick WordPress custom URL variables for /en/page-name & /fr/page-name |
| 2 | - | |
| 2 | + | |
| 3 | - | function flush_rewrite() { |
| 3 | + | function flush_rewrite() {
|
| 4 | - | flush_rewrite_rules( false ); |
| 4 | + | flush_rewrite_rules( false ); |
| 5 | - | } |
| 5 | + | } |
| 6 | - | add_action( 'init', 'flush_rewrite' ); |
| 6 | + | add_action( 'init', 'flush_rewrite' ); |
| 7 | - | |
| 7 | + | |
| 8 | - | function my_insert_query_vars( $vars ) { |
| 8 | + | function my_insert_query_vars( $vars ) {
|
| 9 | - | array_push( $vars, 'lang' ); |
| 9 | + | array_push( $vars, 'lang' ); |
| 10 | - | return $vars; |
| 10 | + | return $vars; |
| 11 | - | } |
| 11 | + | } |
| 12 | - | add_filter( 'query_vars' , 'my_insert_query_vars' ); |
| 12 | + | add_filter( 'query_vars' , 'my_insert_query_vars' ); |
| 13 | - | |
| 13 | + | |
| 14 | - | function add_rewrite_rules($aRules) { |
| 14 | + | function add_rewrite_rules($aRules) {
|
| 15 | - | // $aNewRules = array('(en|fr)/([^/]+)/([^/]+)/?$' => 'index.php?posttype=$matches[2]&slug=$matches[3]&lang=$matches[1]'); |
| 15 | + | // $aNewRules = array('(en|fr)/([^/]+)/([^/]+)/?$' => 'index.php?posttype=$matches[2]&slug=$matches[3]&lang=$matches[1]');
|
| 16 | - | // $aNewRules = array('(en|fr)/project/([^/]+)/?$' => 'index.php?posttype=project&slug=$matches[3]&lang=$matches[1]'); |
| 16 | + | // $aNewRules = array('(en|fr)/project/([^/]+)/?$' => 'index.php?posttype=project&slug=$matches[3]&lang=$matches[1]');
|
| 17 | - | $aNewRules = array('(en|fr)/([^/]+)/?$' => 'index.php?pagename=$matches[2]&lang=$matches[1]'); |
| 17 | + | $aNewRules = array('(en|fr)/([^/]+)/?$' => 'index.php?pagename=$matches[2]&lang=$matches[1]');
|
| 18 | - | $aRules = $aNewRules + $aRules; |
| 18 | + | $aRules = $aNewRules + $aRules; |
| 19 | - | return $aRules; |
| 19 | + | return $aRules; |
| 20 | - | } |
| 20 | + | } |
| 21 | add_filter( 'rewrite_rules_array', 'add_rewrite_rules' ); |