3

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?

9

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.

  • 1
    Thx, very useful answer! I have never heard about those child themes. – Konstantin Jun 26 '16 at 18:41
-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

  • Yeah, so after every update you need to remember to do that change... – Krzysiek Dróżdż Feb 18 at 6:27
  • Modifying parent theme files is not good. Accepted Wordpress best practice is to make changes in copies of the files in the child theme. – mrben522 Feb 18 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.