I edited functions.php and style.css directly in my purchased theme. A new version is out, but I am afraid updating will overwrite my changes. What is the safe way?
DEV3 Developer Forum
How do I update a WordPress theme without losing my customisations?
Every post is reviewed first. Usually reviewed within 24 hours.
1 reply
An update replaces the theme folder, so any edit made inside it is lost. The fix is to keep your changes outside the parent theme.
Use a child theme going forward
A child theme needs only two things:
/*
Theme Name: My Theme Child
Template: parent-theme-folder-name
*/
<?php
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ), wp_get_theme()->get( 'Version' ) );
} );
Template: must equal the parent's folder name. Put your PHP in the child's functions.php (it loads before the parent's). To change a template, copy that file into the child with the same relative path.
Rescue your existing edits
- Download the current theme folder as a backup.
- Download a clean copy of the same version from the vendor.
- Diff them (
diff -ru clean/ edited/or a diff tool). The differences are your customisations. - Move them into a child theme, activate it, then update the parent.
Before any update: take a backup, update on a staging copy first, and read the changelog for template file changes that conflict with your overrides.
Many themes also expose colours and layout through the Customizer or theme.json styles, which survive updates. Prefer those over code edits when possible. A starter you can copy is in the DEV3 snippet library.