Hello @robert.heritage this is a good question, and something I have never personally thought about doing before. Thankfully I been on this forum a long time so seen a lot of questions being asked, and I think you would be better using the new-udelement and setting it on that rather than in the theme. I remember this question:-
This seems like what you are trying to do. There is code put here, but I am sure you could apply the same principal. Hopefully this helps?