I am using a membership plugin and I would like to change the user-profile Urls.

Example Url:


This is how the new Url shall look like:


Any ideas? Thanks and kind regards,


  • What permalink option have you chosen under Settings -> Permalinks ?
    – Howdy_McGee
    Apr 21, 2015 at 15:50

1 Answer 1


The easiest way to do this is with the built-in $wp_rewrite global. Something like this should give you a good start:

function new_rewrite_rules(){
    global $wp_rewrite;
    $keytag = '%user_id%';
    $wp_rewrite->add_rewrite_tag($keytag, '(.+?)', 'user=');
    $structure = $wp_rewrite->root . "username-$keytag/";
    $rewrite = $wp_rewrite->generate_rewrite_rules($structure);                
    if(!is_array($wp_rewrite->rules)) $wp_rewrite->rules = array();
    $wp_rewrite->rules = $rewrite + $wp_rewrite->rules;
    return $wp_rewrite->rules;

You would then access your variable inside the loop via $wp_query->query_vars['user'].

Note that this only makes your URL schema valid, in order to make the new url display you'll have to change the way links are generated in the membership plugin so that they match your schema. Ideally, the plugin will have a filter that lets you change it.

  • Great! I will make a few tests with your code - thank you so far!
    – cgscolonia
    Apr 21, 2015 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.