Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

3 Answers 3

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

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;
      get_currentuserinfo();

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

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

Your Answer

 
discard

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.