Sideband cooling is a popular method for cooling atoms to the ground state of an optical trap. Applying the same method to molecules requires a number of challenges to be overcome. Strong tensor Stark shifts in molecules cause the optical trapping potential, and corresponding trap frequency, to depend strongly on rotational, hyperfine and Zeeman state. Consequently, transition frequencies depend on the motional quantum number and there are additional heating mechanisms, either of which can be fatal for an effective sideband cooling scheme. We develop the theory of sideband cooling in state-dependent potentials, and derive an expression for the heating due to photon scattering. We calculate the ac Stark shifts of molecular states in the presence of a magnetic field, and for any polarization. We show that the complexity of sideband cooling can be greatly reduced by applying a large magnetic field to eliminate electron- and nuclear-spin degrees of freedom from the problem. We consider how large the magnetic field needs to be, show that heating can be managed sufficiently well, and present a simple recipe for cooling to the ground state of motion.