Defer JavaScript in WordPress – fixed

I was recently contacted by a past WordPress site client, desperate because they couldn’t create new posts or pages, and all of their media had gone! Why had the site broken? Was it something I did a couple of years ago coming back to bite me? Time to do some debugging.

I’ll cut a long story short, and say that I did all the usual things here – updated core, theme, and plugins, ran a security check to verify no compromised files, used the excellent Health Check & Troubleshooting plugin, all to no avail. My final, dreadful thought – has somebody made changes to my repository managed, custom child themeā€½

Dear reader, even with **DO NOT EDIT** notices front and centre in the themes files, somebody had gone ahead and made edits to those files, and while they had fixed the issue on the front end, they had badly broken the admin.

“What was the issues that they fixed?” I hear you ask – Deferring loading of JavaScript to decrease the load time of pages. The method used to achieve this is a simple snippet which can be found on numerous sites with a simple search, is often coupled with a request or aim to “get a better GTMetrix score”, and almost every snippet presented is WRONG.

Read more “Defer JavaScript in WordPress – fixed”