How can the use of a child theme in WordPress help prevent the loss of custom files during theme updates?

When updating a WordPress theme, any custom files or modifications made directly to the theme can be lost. To prevent this, one can create a child theme which inherits the functionality of the parent theme while allowing for customizations to be made separately. This ensures that custom files are not affected during theme updates.

// Create a child theme in WordPress
// Step 1: Create a new directory in wp-content/themes for the child theme
// Step 2: Create a style.css file in the child theme directory with the following content:

/*
Theme Name: Child Theme
Template: parent-theme-folder-name
*/

// Step 3: Create a functions.php file in the child theme directory with the following content:

<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
?>