0

I'm trying to use custom links in the php code to link to buddypress profile pages.

Basically, I need a way to create a username constant so I can make links like

domain.com/members/--username--/profile domain.com/members/--username--/settings domain.com/members/--username--/other

with --username-- being the constant which changes the currently logged in user who clicks the link?

I Am sure this could be done in functions.php with a rewrite code but not sure where to begin.

If anyone could help it would be majorly appreciated... This has been racking my brain for weeks. I have no problems implementing the code... Just no idea how to create it?

0

The User data of the currently logged in user in WordPress can be retrieved via wpget_current_user()

So you should be able to do something like this in your theme or wherever.

    $current_user = wp_get_current_user();
    echo '<a href="http://example.com/members/' . $current_user->user_login . '/profile">Your profile</a>.';

And build your link that way.

HTH

  • I tried as you suggested but it didn't work :( – Crafty Mc Jul 31 '16 at 4:07
  • some more information would be good. What exactly did you do? What did not work? – Helmi Jul 31 '16 at 7:43
  • hey, so here's the current code, $actions = array( 'edit-profile' => html( 'a', array( 'href' => appthemes_get_edit_profile_url() ), __( 'Edit Profile', APP_TD ) ), 'logout' => html( 'a', array( 'href' => wp_logout_url() ), __( 'Logout', APP_TD ) ), ); and i tried replacing it with $current_user = wp_get_current_user(); echo "<a href="http://example.com/members/" . $current_user->user_login . '/profile">Your profile</a> but i get 500 internal server error. I'm trying to replace the edit profile link with a buddypress profile link. – Crafty Mc Jul 31 '16 at 11:41
  • where's this code from? We're completely missing the context here. What the code that I gave you does is just output a link. The Code above just fills $actions with an array. Replacing one with the other doesn't work. The code above doesn't render a link to the frontend but only define an array. That can't work. – Helmi Aug 1 '16 at 7:40
  • Ahh i see. and it's from the appthemes ideas theme. Is there a way to perhaps remove the array and recode it to use the php code you supplied. saying that, when i tried your code outside of any function i get 500 internal server error. – Crafty Mc Aug 1 '16 at 10:37

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.