I am trying to add a menu item titled something like "my posts" or "my profile" that would take the logged in user to their author page


You can use wp_nav_menu_items filter for this, and check if user logged in, and use get_author_posts_url($autho_id) as bravokeyl suggested:

add_filter('wp_nav_menu_items', function( $items, $args ) {
    $index = 'top-menu'; // menu index key, if you're not sure then var_dump( $args->theme_location )
    global $current_user;
    if ( $current_user->ID && $index === $args->theme_location ) {
        $items .= sprintf(
            '<li id="menu-item-my-posts" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-my-posts menu-item-my-posts"><a href="%s">%s</a></li>',
            get_author_posts_url( $current_user->ID ),
            'My Posts'
    return $items;
}, 10, 2);

Hope that helps.

  • Thanks Samuel. I tried entering the above code into the functions.php (really its a site specific plugin but it should link to functions.php). It didnt seem to work though. Am I adding it to the wrong place? Or do I have to do something before entering the above code?
    – Manny
    Nov 27 '16 at 20:58

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.