Just make sure that the order of the interaction definitions are correct.
I would suggest reading the thread at Including parameters of a new molecule in gromacs topology files as well as https://manual.gromacs.org/documentation/current/reference-manual/topologies/topology-file-formats.html and GROMACS File Formats: Understanding topology, itp, and gro files - Compchems.