0

Is there a way to create an menu button that link to different pages to each unique user?

So far I have used the plugs-in: User Specific Content, Peter's Login Redirect and Them my Login.

Basically, when an user login they can get information only avaliable to them but there is no way to go back if the user moves to another page. How to make the link for them to go back inside menu?

Just to make sure, I want to make an button on the menu bar that they can click to get to user personal page. I'm quite new with wordpress and not very familiar with html/css/etc.

  • how is their personal page generated? is the URL unique to each user? – Milo Jan 2 '15 at 17:44
  • Ok, the procedure I was using doesn't work anymore. Because User Specific Content Login is not supported by WP Version 4. How to make an user login where there is an page for every user that only the user can see? – user129963 Jan 2 '15 at 23:00
0

If you want to do something like a "Back to previous page"-link that will probably not work with the WP menu system.

But you could modify/add your theme and use $_SERVER['HTTP_REFERER'] (PHP manual) to link back to the site, where the user clicked the link to the actual page. But that information can also be altered or not be available due to privacy settings/plugins or other things, so make sure to catch that.


Update: Thanks to the much clearer information from the comments, you could do this.

  1. Create a page template, called "Redirect to User Page" or something like that. Have a look here to see how that works.
  2. Put this in the template file besides the necessary pieces (you might need to adjust it, to fit your needs):

if(is_user_logged_in()) { $user_info = get_userdata(get_current_user_id()); $url = 'http:// www. example. com/users/'.$user_info->user_login.'/'; $string = '< script type="text/javascript" >'; $string .= 'window.location = "' . $url . '"'; $string .= '< /script >'; }

This will first check if a user is logged in, then retrieve his user data and finally redirect to a (sub)page you define where his login name is the permalink.

  1. Set up a page that uses the custom page template and choose a nice permalink for it.

You can then link to that page in a menu. You should furthermore define an else-case or arrange to not show that link when you are not logged in.

Make sure to look up the functions I used here. Can´t post more than two links right now, but you should really understand what this does and why it does, otherwise you won´t have much fun using it.

  • Thanks, I updated the question a bit. Was the second part of the answer still apply? – user129963 Jan 2 '15 at 17:36
  • Ah, I see. Could you give some more information about that "user personal page"? How is it created, how the URL is made up and things like that? – flomei Jan 2 '15 at 17:45
  • Basically, I want to create an login where the user can login and see how the work I'm doing for them is progressing. But they can't see my other customers. I think this part is mostly done. But once, they finish looking at their personal page and go to homepage of site for example, there is no way for them to go back to their personal page again. – user129963 Jan 2 '15 at 17:51
  • I created logins using Theme My Login plug-in. Then I created pages for each user I have with the User Specific Content Plug-in. Then I redirected the pages such that its there when they login, using Peter's Login Redirect. – user129963 Jan 2 '15 at 17:54
  • Ok, can you give me a sample URL? Does ist contain the user name or his ID? That would really help... – flomei Jan 2 '15 at 17:55
0

If you've got a wp_nav_menu instance for your menu, you can add a filter to dynamically add menu items when the menu is printed to the page.

The filter for all nav menus is wp_nav_menu_items.

For specific menu slugs, the filter is wp_nav_menu_{$menu->slug}_items. For example, if your menu slug is primary, the filter would be wp_nav_menu_primary_items

Here's an example that maybe does what you need, based on your description in comments.

function wpd_nav_menu_items( $items ){
    // if a user is logged in
    if( is_user_logged_in() ){
        // get the current user's data
        global $current_user;
        get_currentuserinfo();
        // menu item's url and title
        $url = home_url( '/' . $current_user->user_login . '/' );
        $title = $current_user->user_firstname . '\'s page';
        // add the menu item onto the end
        $items .= '<li><a href="' . $url . '">' . $title . '</a></li>';
    }
    return $items;
}
add_filter( 'wp_nav_menu_items', 'wpd_nav_menu_items' );

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.