Quote from
qualmy91 on April 18, 2021, 7:23 am
Hey @hawks-cast,
you can use the following code to change a menu entry:
add_filter( 'nav_menu_link_attributes', 'asgaros_menu_profile', 10, 3 );
function asgaros_menu_profile( $atts, $item, $args ) {
if (!strpos($atts['href'], '--asgaros-profile--')) {
return $atts;
}
$user = wp_get_current_user();
$profile_link = home_url() . "/forum/profile/" . $user->user_nicename;
$atts['href'] = $profile_link;
return $atts;
}
After adding this code you only have to add “–asgaros-profile–” to the URL of the menu entry and it will be replaced with the profile link.
Hey @hawks-cast,
you can use the following code to change a menu entry:
add_filter( 'nav_menu_link_attributes', 'asgaros_menu_profile', 10, 3 );
function asgaros_menu_profile( $atts, $item, $args ) {
if (!strpos($atts['href'], '--asgaros-profile--')) {
return $atts;
}
$user = wp_get_current_user();
$profile_link = home_url() . "/forum/profile/" . $user->user_nicename;
$atts['href'] = $profile_link;
return $atts;
}
After adding this code you only have to add “–asgaros-profile–” to the URL of the menu entry and it will be replaced with the profile link.
Hawks Cast has reacted to this post.