Thanks for the responses, in the end it boiled down to me just being an idiot.
I was using a function which echo
'd the url to pass urls into my function.
Swapped that for one that just presents url as a string, and it works like a champ.
Thanks again for tolerating my idiocy...