How to preserve PHP modifications while upgrading WordPress?

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

To provide customized search results, filtered content on the main page, ordering archives, and search results by meta tags, echoing custom JavaScript to the page which supports the site logic heavily, etc.

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?

2 Answers
2

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.

Leave a Comment