Radio observations of galaxy clusters show that the intracluster medium is permeated by magnetic fields. The origin and evolution of these cosmological magnetic fields is currently not well understood, and so their impact on the dynamics of structure formation is not known. Numerical simulations are required to gain a greater understanding and produce predictions for the next generation of radio telescopes. We present the galactic chemodynamics smoothed particle magnetohydrodynamics (SPMHD) code (gcmhd+), which is an MHD implementation for the cosmological smoothed particle hydrodynamics code gcd+. The results of 1D, 2D and 3D tests are presented and the performance of the code is shown relative to the athena grid code. gcmhd+ shows good agreement with the reference solutions produced by athena. The code is then used to simulate the formation of a galaxy cluster with a simple primordial magnetic field embedded in the gas. A homogeneous seed field of 3.5 × 10−11 G is amplified by a factor of 103 during the formation of the cluster. The results show good agreement with the profiles found in other magnetic cluster simulations of similar resolution.