Programmatically adding menu items function replicates in multiple menus
You can use the second input argument $args to target the specific menu. Here’s an example with some checks that you can adjust to your needs: add_filter( ‘wp_nav_menu_objects’, function( $sorted_menu_items, $args ) { if( ‘primary’ === $args->theme_location // Alternative && ‘some_menu_slug’ === $args->menu->slug // Alternative ) { // Your stuff here … } return $sorted_menu_items; … Read more