Menu Button that link to different pages for unique user?

admin2025-01-08  9

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.

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.

Share Improve this question edited Jan 2, 2015 at 17:35 user129963 asked Jan 2, 2015 at 17:27 user129963user129963 12 bronze badges 2
  • how is their personal page generated? is the URL unique to each user? – Milo Commented Jan 2, 2015 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 Commented Jan 2, 2015 at 23:00
Add a comment  | 

2 Answers 2

Reset to default 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.

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' );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736269947a1391.html

最新回复(0)