The visit of the Magi took place after the Presentation of the Child in the Temple (Luke 2:38). No sooner were the Magi departed than the angel bade Joseph take the Child and its Mother into Egypt (Matthew 2:13). Once Herod was wroth at the failure of the Magi to return, it was out of all question that the presentation should take place. Now a new difficulty occurs: after the presentation, the Holy Family returned into Galilee (Luke 2:39). Some think that this return was not immediate. Luke omits the incidents of the Magi, flight into Egypt, massacare of the Innocents, and return from Egypt, and takes up the story with the return of the Holy Family into Galilee. We prefer to interpret Luke's words as indicating a return to Galilee immediately after the presentation. The stay at Nazareth was very brief. Thereafter the Holy Family probably returned to abide in Bethlehem. Then the Magi came. It was "in the days of King Herod" (Matthew 2:1), i.e. before the year 4 B.C. (A.U.C. 750), the probable date of Herod's death at Jericho. For we know that Archelaus, Herod's son, succeeded as ethnarch to a part of his father's realm, and was deposed either in his ninth (Josephus, Bel. Jud., II, vii, 3) or tenth (Josephus, Antiq., XVII, xviii, 2) year of office during the consulship of Lepidus and Arruntius (Dion Cassis, lv, 27), i.e., A.D. 6. Moreover, the Magi came while King Herod was in Jerusalem (vv. 3, 7), not in Jericho, i.e., either the beginning of 4 B.C. or the end of 5 B.C. Lastly, it was probably a year, or a little more than a year, after the birth of Christ. Herod had found out from the Magi the time of the star's appearance. Taking this for the time of the Child's birth, he slew the male children of two years old and under in Bethlehem and its borders (v. 16). Some of the Fathers conclude from this ruthless slaughter that the Magi reached Jerusalem two years after the Nativity (St. Epiphanius, "Haer.", LI, 9; Juvencus, "Hist. Evang.", I, 259). Their conclusion has some degree of probability; yet the slaying of children two years old may possibly have been due to some other reason — for instance, a fear on Herod's part that the Magi had deceived him in the matter of the star's appearance or that the Magi had been deceived as to the conjunction of that appearance with the birth of the Child.
Read much more on the Magi at Newadvent, or more on the Epiphany Feast. Feliz fiesta!