We have fabricated several heterostructures made of two opal slabs separated by a defect. The optical properties of the resulting materials have been characterized by recording their near-infrared (NIR) transmission spectra and by simulating them using the finite-difference time-domain method. The presence of the extrinsic defect led to an impurity mode within the photonic stop band, which was observed as a pass band in the NIR spectra. We show that the amplitude of the pass band is maximal when the two opals confining a defect monolayer made of smaller colloids have the same number of layers. On the other hand, this middle position of the defect layer does not correspond to an optimal cavity when the guest particles are larger than the host ones, as the presence of the defect induces a deterioration of the crystalline organization of the upper opal slab. To minimize the presence of unintentional defects in the heterostructures, we incorporated a planar defect made of particles of a different nature but of the same size than those forming the host opal. A pass band within the band gap was also observed in the NIR transmission spectra of the samples due to the difference between the refractive indexes of the guest and host colloids.