In the current work, nanocomposites of Mg−Al and Mg−Fe layered double hydroxides (LDHs) anchored on silica foam (SF), denoted as MAL/SF and MFL/SF, respectively, were fabricated using a two‐step route. The obtained LDHs/SF nanocomposites were characterized by XRD, TEM, SEM, EDS, elemental mapping, and N2 adsorption‐desorption techniques. Sorption of the heavy‐metal Pb(II) and Cr(VI) on the LDHs/SF was determined at 25 °C and pH 5.5 using a batch technique. In comparison with bulk Mg−Al and Mg−Fe LDHs, the LDHs in the MAL/SF and MFL/SF exhibit significantly enhanced sorption capacities. In addition, the LDHs/SF nanocomposites show a good recyclability for removing heavy metals. The construction of LDHs/SF nanocomposites is an effective strategy for improving the sorption capacity of LDHs, and the nanocomposites are potential sorbents for wastewater treatment.