Since a couple of weeks I'm trying to create my own rewritings on pages. I read a lot about rewriting with posts and custom post-types.

BUT: I have pages that I call with variables. How is it possible to bring these variables into a permalink-structure?

Currently, I have:


but I want to have something like


I have fount the hook post_link which seems to be used on pages and page_link for pages. But page_link doesn't work in the same way. How can I do, what I want to do?

Please help!


Yes this is possible using the $wp->add_query_var function used together with add_rewrite_rule . Here you have an example:

Passing and retrieving query vars in wordpress

If you want more help here is a cut from one of my old plugins:

function createRewriteRules() {
        global $wp_rewrite;

 $new_rules = array(
                '(.?.+?)/(stenskott)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
                '(.?.+?)/(bilclas)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
                '(.?.+?)/(inbrott-i-bil)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
                '(.?.+?)/(om-glas)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
                '(.?.+?)/(kontakt)$' => 'index.php?pagename='.$wp_rewrite->preg_index(2).'&ort='.
       // Always add your rules to the top, to make sure your rules have priority
        return $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

add_action('generate_rewrite_rules', 'createRewriteRules');

function query_vars($public_query_vars) {

        $public_query_vars[] = "ort";

        return $public_query_vars;
add_filter('query_vars', 'query_vars');

add_action('init', 'add_endpoints');
function add_endpoints()
    add_rewrite_endpoint('ort', EP_PAGES);
  • Hi Robin, thanks for your answer. But I afraid that this is not what I'm looking for. I've tried what you have written, but my url is not rewritten from www.mysite.com/pagename/?arg1=value1 (entered into the browser adress line) to www.mysite.com/pagename/value1. Any idea? – user3114592 Dec 29 '13 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.