Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Handles URL Rewriting in WordPress 3.0 like this:
fastigheter-spanien/X -> property/X&lang=sv
fastigheter-usa/X -> property/X&lang=sv
properties-spain/X -> property/X&lang=en
properties-usa/X -> property/X&lang=en
Answer for:
By: Mike Schinkel
Copy this to your theme's functions.php file or put the code in a plugin.
Be sure to rename the "my_*()" functions to something unique that makes
sense in your sites context.
add_action('init', 'my_init');
function my_init() {
global $wp,$wp_rewrite;
$wp_rewrite->add_permastruct('fastigheter', 'fastigheter-%lang%/%property%');
$wp_rewrite->add_permastruct('properties', 'properties-%lang%/%property%');
'label' => 'Property',
'public' => true,
'show_ui' => true,
'query_var' => 'property',
'rewrite' => array('slug' => 'property'),
'hierarchical' => true,
'supports' => array(
* The line that follows should be deleted and go in a plugin activation hook
* or you can just update permalinks in the admin once (after adding this
* code) by going here:
* (replace above with your domain)
add_filter('request', 'my_request');
function my_request($request) {
if (isset($request['lang']))
switch ($request['lang']) {
case 'spanien':
case 'spain':
$request['lang'] = 'sv';
case 'usa':
$request['lang'] = 'en';
return $request;
function get_property_lang() {
global $wp_query;
return (isset($wp_query->query_vars['lang']) ? $wp_query->query_vars['lang'] : '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.