Hi cfwillia,
Its not about the themes, i would suggest you to use WordPress ad management plugins to insert ads properly rather than to adding adsense script manually.
disconnect your webserver from Cloudflare and point domain nameserver directly to main server and Change your Current Themes to Default, check detailed instruction here https://www.webminto.com/how-to-fix-the-504-gateway-timeout-error-in-wordpress/ if this dont fix, chat with your web hosting, there might be issue at their end.
Hi, 504 error can cause by many reason try deactivating all the plugins temporary, if you are using proxy then disable it, even if your website is on CDN Network disable it, this guide may help you to fix 504 error.