Created
February 1, 2012 21:48
-
-
Save stresslimit/1719681 to your computer and use it in GitHub Desktop.
quick WordPress custom URL variables
This file contains 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
<?php // quick WordPress custom URL variables for /en/page-name & /fr/page-name | |
function flush_rewrite() { | |
flush_rewrite_rules( false ); | |
} | |
add_action( 'init', 'flush_rewrite' ); | |
function my_insert_query_vars( $vars ) { | |
array_push( $vars, 'lang' ); | |
return $vars; | |
} | |
add_filter( 'query_vars' , 'my_insert_query_vars' ); | |
function add_rewrite_rules($aRules) { | |
// $aNewRules = array('(en|fr)/([^/]+)/([^/]+)/?$' => 'index.php?posttype=$matches[2]&slug=$matches[3]&lang=$matches[1]'); | |
// $aNewRules = array('(en|fr)/project/([^/]+)/?$' => 'index.php?posttype=project&slug=$matches[3]&lang=$matches[1]'); | |
$aNewRules = array('(en|fr)/([^/]+)/?$' => 'index.php?pagename=$matches[2]&lang=$matches[1]'); | |
$aRules = $aNewRules + $aRules; | |
return $aRules; | |
} | |
add_filter( 'rewrite_rules_array', 'add_rewrite_rules' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment