Capillary penetration of liquids in porous media is of great importance in many applications and the ability to tune such penetration processes is increasingly sought after. In general, liquid penetration can be retarded or restricted by the evaporation of volatile liquid at the surface of the porous media. Moreover, when capillary penetration occurs in a porous layer with non-uniform cross section, the penetration process can be accelerated or impeded by adjusting the section geometry. In this work, on the basis of Darcy's Law and mass conservation, a theoretical model of capillary penetration combining evaporation effects in two-dimensional homogeneous porous media of varying cross-section is developed and further examined by numerical simulations. The effects of sample geometry and liquid evaporation on capillary penetration are quantitatively analyzed. Results show that the penetration velocity is sensitive to the geometry of the porous layer, and can be tuned by varying the evaporation rate for a given geometry. Under given evaporation conditions, penetration is restricted to a limited region with a predictable boundary. Furthermore, we find that the inhibition of liquid penetration by evaporation can be offset by varying the geometry of the porous layer. In addition, the theoretical model is further extended to model the capillary flow in three-dimensional porous media, and the interplay of geometry and evaporation during the capillary flow process in 3D conditions is also investigated. The results obtained can be used for facilitating the design of porous structures, achieving tunable capillary penetration for practical applications in various fields.