1

I am using wordpress wp-admin to create the menu. It is under Appearance/menu.

I have a link that points to /members/ but what I really need is a link to /members/$logged_user...

For example /members/user_1 or /members/user_2.

How can I do that? I dont know if it is important, but I am using buddypress plugin.

Creating the menu item

0

3 Answers 3

6

I have written a short script for adding dynamic buddypress links in wordpress menu. Hope it helps

I have added custom links in wordpress menu replacing username in link with --username-- example http://website_name.com/members/--username--/messages/

then add this code in function.php

add_filter( 'nav_menu_link_attributes', 'menu_override', 10, 3 );

function menu_override( $atts, $item, $args ) {
    $user = wp_get_current_user();
    $newlink = str_replace("--username--", $user->user_login, $atts[href]);
    $atts[href] = $newlink;
    return $atts;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Concise and clean. WordPress doesn't support shortcodes in menu item urls because the brackets (i.e. [/]) are stripped out but it would be great to see support for an alternative implementation based on your approach. You should seriously consider fashioning this into a plugin. e.g. WordPress Menu URL Shortcodes
Thanks but i believe in latest version of Wordpress. We have option of buddypress URL in wordpress menu by default
dude i was searching for something like this for 2 days buddy-press should nattily support this i understand that they have login logged out links but whats needed is custom linking functions to make dynamic links to specific groups, specific profiles and message to host links
0

The default menu doesn't really have that option. But you can make your own walker function, searching for the keyword and replacing it with the current user.

See http://codex.wordpress.org/Function_Reference/wp_nav_menu#Using_a_Custom_Walker_Function

But it would probably be faster and more manageable to just place the link outside the menu call with some static html and the needed php.

Comments

0

You can use the BuddyPress Custom Profile Menu plugin to get close to this functionality, otherwise you will have to write custom code that uses actions/filters of wp_nav_menu().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.