Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am building a client portal where my clients can log in and see all their pending projects, completed projects and create new projects.

Though I'm stuck at the start.

The dropdown menu is called "My Projects"
If "User 1" is logged in and they click on "My Projects" then I need that link to link to: or USERNAME)/

This will be their dedicated page so if user 1's username is johndoe the link will be my-projects/johndoe/

If user 2 (janedoe) is logged in. when they click "My Projects" they will be taken my-projects/janedoe/ and so on, so fourth.

So basically I need a %username% permalink I can put into a custom menu link that will change %username% with the current logged in user's username.

Can this be done?

share|improve this question

2 Answers 2

I think you can make this much easier than you are. Just create a my-projects page and forget about the custom rewrite. Why? Because a user will only need to see their own projects. No need for a just rewrite because you can get the current user any time.

Embed the project rendering into a shortcode and just pop it into whatever page you want.

add_action('init', 'wpse105306_add_shortcode');
function wpse105306_add_shortcode()
    add_shortcode('wpse105306_projects', 'wpse105306_projects');

function wpse105306_projects()
    $user = wp_get_current_user();

    $projects = wpse105306_get_projects_somehow($user);

    // do stuff with $projects

function wpse105306_get_projects_somehow($user)
    // whatever you need here

That said, if you really want that url, you'll need to do a custom rewrite.

// make the rewrite work
add_action('init', 'wpse105306_add_rewrite');
function wpse105306_add_rewrite()

// make sure WordPress doesn't eat the wpse105306_portal query var
add_filter('query_vars', 'wpse105306_add_var');
function wpse105306_add_var($vars)
    $vars[] = 'wpse105306_portal';
    return $vars

Then hook in someplace late (eg. template_redirect) and if you have the query var for the portal, render the customers projects.

add_action('template_redirect', 'wpse105306_catch_portal');
function wpse105306_catch_portal()
    $username = get_query_var('wpse105306_portal');
    if (!$username) {
        return; // things go on as normal

    $projects = wpse105306_get_projects_somehow($username);

    // do stuff with $projects

function wpse105306_get_projects_somehow($username)
    // whatever you need here

You might also be able to do something with add_rewrite_tag. A custom rewrite will mean you have to do some other stuff to make it work in menus. The shortcode approach above means you can use the menu system as normal.

share|improve this answer

WordPress has a built in function for getting the current user:

<?php wp_get_current_user(); ?>

My approach would then be to create a variable such as:

<?php $userid = wp_get_current_user(); ?>

Then in your HTML just do this <a href =userportal?<?php echo $userid ?> >menu <\a>

Then just use the php GET variable to get the user id from the url and you can use that to get whatever details you need about the user.

That way instead of making a new page for every user you can use AJAX and request the portfolio of any user based on their ID. Much easier and more scaleable in the long run.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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