web application – How to replace certain backup files on a website every 30 minutes?

I have a website built with WordPress, unfortunately somebody hacked it several times, deleted my adsense code and put his own adsense.

I tried many security techniques, changed database name, did some stuff to prevent anybody from editing files through admin panel etc…

But this guy infiltrated and put his adsense code again yesterday. Because of this, I couldn’t make any money yesterday, google adsense doesn’t appear immediately, it takes more than 12 hours.

He only changes 2 files, header.php (template’s file) and ads.txt (on the main directory).

How can I renew these 2 files (replace old ones with backup ones) every 30 minutes automatically?

Thank you!