您可以使用wp_nav_menu_items 对此进行筛选,并检查用户是否已登录,并使用get_author_posts_url($autho_id) 正如bravokeyl所建议的:
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);
希望这有帮助。