A new custom power device (CPD) is introduced for real-time control of reactive power and improving the overall network voltage quality of smart grid (SG) at fundamental and harmonic frequencies, respectively. The idea is to take advantage of the online smart meter data transmitted from each bus to the SG central control to concurrently perform the static synchronous compensator and the active power line conditioner operations by optimal compensations of fundamental reactive power and harmonic currents at selected optimal buses. The proposed strategy involves two particle swarm optimization algorithms. The first algorithm is implemented for the worse operating condition to determine the optimal locations and sizes of CPDs while the second algorithm relies on smart meter information to continuously compute fundamental and harmonic reference currents for real-time operation and control of the allocated CPDs. The objective functions are cost minimizations associated with bus voltage regulations, network total harmonic distortions voltage and custom device sizing while the constraints include upper limits for CPD sizes, fundamental, and harmonic bus voltages. Detailed simulations are performed in MATLAB/Simulink to evaluate the performances of allocated CPDs in controlling the reactive power and voltage quality of a distorted 15-bus SG with six nonlinear loads according to the IEEE-519 standard.