WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to add a link to BuddyPress' My Favourite Topics in a Custom Menu. Is there a way to use the current logged in user's username in the link?

I mean like the %category% in the permalinks.

share|improve this question

Yes there is a way how you can do it. To implement it properly I would recommend you to read The Rewrite API: The Basics article. Especially pay attention on Add Rewrite Tag section.

share|improve this answer

You can access the user's display name through get_currentuserinfo() function. You would first need to set the global then you can access the display name.

<?php global $current_user;

      echo 'Hello, ' . $current_user->display_name . "\n";
share|improve this answer

EDIT: Sorry, didn't noticed the date of the question before answering.

function add_favorites_link( $items, $args ) {
    // Check is user logged in
    if ( is_user_logged_in() ) {
        $user = wp_get_current_user();
        $ID = $user->ID;
        $fav = '<a href="'.bbp_get_favorites_permalink( $ID ).'">Favorites</a>';

        // Change the Menu Location to yours
        if ( $args->theme_location == 'primary' ) {
            $items .= '<li>'.$fav.'</li>';
        return $items;
add_filter( 'wp_nav_menu_items', 'add_favorites_link', 10, 2 );

That's a dirty workaround, but it will get you started.

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.