Extended black hole thermodynamics from extended Iyer-Wald formalism