I made a lot of custom modifications in the PHP code of my WordPress blog. Namely in: archive.php, blog.php, footer.php, functions.php, header.php, search.php
What can I do to make the custom changes in the PHP code survive the upgrade process? Should I save them one by one and after making the upgrade should I paste the customized lines or code samples one by one?
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Each of the files you have mentioned are theme files. When you upgrade WordPress itself, it will not touch any themes (or plugins) you have installed, whether or not you have modified them.
If this was a theme you created yourself, then you have no worries at all.
However, if this was a theme created by someone else, for example a WordPress default theme, you can still update WordPress… but you need to be careful before updating the theme (if any updates are available for it).
Yes, you can save your modifications and then re-apply them after updating the theme, but the best thing to do is not to make these modifications directly in the first place, and rather use a child theme.
It’s not too hard to set up a child theme, and doing so will mean that any of your modifications are kept safe. Basically, you just copy the pre-existing archive.php, search.php etc., make your modifications, and store them in your child theme’s folder. WordPress will then use these modified files instead of the originals. When you update the original theme, it’s then up to you whether you fold any new changes and enhancements into your child theme.
Rather than copying most of your files to a child theme, A quicker (but probably not so clean) fix is simply to insert a line of code in eg. functions.php that is include=’custom.php’;
You simply put all your custom code in custom.php.
If you update your theme all you need to do is reinsert the include line