WordPress.org

Ready to get started?Download WordPress

Forums

Place current username into a link (5 posts)

  1. HorrorUK
    Member
    Posted 2 years ago #

    I have some code in a plugin that I'm using, and I need to be able to place the current username within the link.

    This is the link I'd like to have at the end:
    http://domain.com/members/joe/my-events/

    I can get it as far as adding the /members/section as below, but can't figure out what I need to do to add the current user.

    'parent_url' => $bp->displayed_user->siteurl . '/members/my-events' . '/',

    I've tried the one below, but that just gives me a white screen. I'm not a developer, just learning from what I see in examples.

    'parent_url' => $bp->displayed_user->siteurl . '/members/' $current_user . 'my-events' . '/',

    This is on a BuddyPress site, not sure if that helps.

  2. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    You can use get_currentuserinfo():

    global $current_user;
    $current_user = get_currentuserinfo();
    // Username
    $current_username = $current_user->user_login;

    If there is a BuddyPress-specific function or method, you'll probably want to check the BuddyPress support forums for help with that.

  3. HorrorUK
    Member
    Posted 2 years ago #

    Thanks Chip.

    Where would that go within this?

    'parent_url' => $bp->displayed_user->siteurl . '/members/my-events' . '/',

  4. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    Where would that go within this?

    No clue. That looks like a BuddyPress construct, and I don't see any reference to current user username there.

    Now, looking at your second code block:

    'parent_url' => $bp->displayed_user->siteurl . '/members/' $current_user . 'my-events' . '/',

    You could try using $current_username in place of $current_user?

  5. HorrorUK
    Member
    Posted 2 years ago #

    Thanks, I'll have a play with it and see what I get :o)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.