Shunt capacitors are usually installed in distribution grids for power factor correction. On the other hand, the number of harmonic‐producing sources such as wind turbines (WTs), photovoltaic (PV) panels, storage units, and electronic loads is rapidly growing in distribution grids. Since improper placement and sizing of shunt capacitors in harmonic‐polluted grids may aggravate power quality conditions and lead to harmonic resonance, special attention should be paid to this optimization problem when harmonics are present. In this paper, a framework based on shuffled frog leaping algorithm (SFLA) is proposed for optimal placement of fixed capacitor banks. Moreover, a resonance index (RI) is proposed for assessment and mitigation of potential harmonic resonance based on resonance mode analysis (RMA). The resonance mitigation method helps in avoiding power quality constraint violations and directs the algorithm toward the feasible solution space. It thus results in a higher efficiency, and the chance of reaching (near) globally optimum solutions increases. The proposed algorithm is particularly useful when detailed data regarding the harmonic injection pattern of nonlinear sources is not available. The proposed framework is implemented on the IEEE 18, 34, and 69‐bus test systems, and the results demonstrate its advantages, especially in larger grids.