How to preserve PHP modifications while upgrading WordPress?

The question:

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?

The Solutions:

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.

Method 1

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.

Method 2

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment