Skip to content

Instantly share code, notes, and snippets.

@stresslimit
Created February 1, 2012 21:48
Show Gist options
  • Save stresslimit/1719681 to your computer and use it in GitHub Desktop.
Save stresslimit/1719681 to your computer and use it in GitHub Desktop.
quick WordPress custom URL variables
<?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