Young animals can learn about flavors from the maternal diet that appear in the amniotic fluid and mother’s milk, which may reduce neophobia for similarly flavored food types at weaning. Flavor learning may be beneficial for piglets, which after the rather abrupt weaning in pig husbandry frequently show a period of anorexia, reduced health, and stress-induced behaviors. We investigated the effects of pre- and postnatal flavor exposure through the maternal diet on acceptance of a similarly flavored food and subsequent growth, health and behavior of newly weaned piglets. Sows were offered anise-flavored (F) or control (C) food during late gestation. Piglets were cross-fostered after birth, with each sow fostering 5 piglets from an F sow and 5 from a C sow. During lactation, sows were offered F or C food, resulting in FF, CF, FC and CC piglets. Piglets were weaned on day 25 and were given both control and flavored food for two weeks using a double food choice approach. The flavored food was not preferred. Yet, prenatally exposed animals showed a higher food intake and a higher body weight in the first days after weaning, and a lower occurrence of diarrhoea than non-exposed piglets. Prenatal exposure also increased the latency to fight, and reduced oral manipulation of pen mates and mounting during the first two weeks after weaning. Prenatal exposure, but not postnatal exposure alone, to anisic flavor through the maternal diet reduced weaning-associated problems in piglets and enhanced their health and welfare in the period after weaning.