When I remove the code and rescan the site its back to 5-6 seconds. I tried a plugin on the site but it slows it down to around 12-13 seconds.
I have attached the link to the report to see what you can recommend on speeding up this.
I activated TwentySeventeen theme and ran GTMetrix and it loaded in 1.7seconds, I switch back to Royal and GT Metrix jumps up 12.7seconds.