1

I’m pretty new to WordPress, and yesterday I tried creating my first child theme from the AccessPress-Enlighten 1.1.9 parent theme (I cheated by using the Child Themify plugin), made a slight modification to the child theme’s header.php file, and it worked! However, this raises some questions for me:

  1. I understand that parent theme updates are not supposed to affect child theme modifications, but does that mean that if I have header.php in my child theme (wp-content/themes/enlighten-child/header.php), then no parent theme updates to the header.php will affect my website?

  2. Does the same apply to modifying widget PHP code?

  3. If either of the above answers are “yes”, how can I easily benefit from other enhancements/fixes that come with parent theme updates to the PHP files with the same names as those I’ve modified, without losing my changes? I guess I’m wanting to have my changes merged with those made by the theme vendor, but I expect that's probably too much to ask.

  4. After activating the child theme, I noticed that some of the customisations I’d made to the parent theme disappeared. (When I say “customizations”, I mean changes made via Appearance > Customise > Header Setting > Header Info Section, for example, not changes to PHP code.) Is that normal and what parent theme customizations can I expect to lose when creating/activating a child theme?

  5. I understand that updating a parent theme will not touch the child theme files, but if I’m not even using a child theme, will updating the theme via WordPress always replace the header.php file, or will it only be replaced if the file has changed since what it was when it came out when the currently installed version was distributed?

I’ve had a quick read of this https://codex.wordpress.org/Child_Themes official child theme documentation.

So that you know the kind of changes I’m talking about, here’s the unedited header.php file I changed. I changed line 64 so it says “Call Me” instead of “Call Support”.

<?php
/**
 * The header for our theme.
 *
 * This is the template that displays all of the <head> section and everything up until <div id="content">
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package enlighten
 */

?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">

<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<div id="page" class="site">
    <a class="skip-link screen-reader-text" href="#main"><?php esc_html_e( 'Skip to content', 'enlighten' ); ?></a>

    <header id="masthead" class="site-header" role="banner">

        <!-- Site Logo -->
        <div class="ak-container">
            <?php
                $enlighten_header_text = get_theme_mod('enlighten_header_text');
                $enlighten_header_social_link_enable = esc_attr(get_theme_mod('enlighten_enable_heade_social_icon'));
                if($enlighten_header_text || $enlighten_header_social_link_enable){
             ?>
            <div class="social_htext_wrap">
            <?php if($enlighten_header_text){ ?>
                <div class="header_text">
                    <span class="text_wrap"><?php echo esc_attr($enlighten_header_text); ?></span>
                </div>
            <?php } ?>
            <?php if($enlighten_header_social_link_enable){ ?>
                <div class="header_social_link">
                    <?php do_action('enlignten_header_social_link_action'); ?>
                </div>
            <?php } ?>
            </div>
            <?php } ?>

            <div class="logo_info_wrap">
              <?php
              //Header Logo
              do_action('enlighten_action_custom_logo');

                $enlighten_enable_info = esc_attr(get_theme_mod('enlighten_enable_header_info'));
                if($enlighten_enable_info)
                  { ?>
                      <div class="header_info_wrap">
                          <?php $enlighten_number = get_theme_mod('enlighten_phone_header');
                          if($enlighten_number){ ?>
                            <div class="phone_header wow fadeIn">
                                <div class="fa_icon"><i class="fa fa-phone" aria-hidden="true"></i></div>
                                <div class="title_phone">
                                    <span class="pnone_title"><?php esc_html_e('Call Support','enlighten'); ?></span>
                                    <span class="phone"><?php echo esc_attr($enlighten_number); ?></span>
                                </div>
                            </div>
                          <?php }
                          $enlighten_email = get_theme_mod('enlighten_email_header');
                          if($enlighten_email){ ?>
                            <div class="email_header wow fadeIn">
                                <div class="fa_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></div>
                                <div class="title_email_wrap">
                                    <span class="title_email"><?php esc_html_e('Email Support','enlighten'); ?></span>
                                    <span class="email_address"><?php echo esc_attr($enlighten_email); ?></span>
                                </div>
                            </div>
                            <?php }
                          $enlighten_location = get_theme_mod('enlighten_localtion_header');
                          if($enlighten_location){ ?>
                            <div class="location_header wow fadeIn">
                                <div class="fa_icon"><i class="fa fa-map-marker" aria-hidden="true"></i></div>
                                <div class="title_location_wrap">
                                    <span class="title_location"><?php esc_html_e('Location','enlighten'); ?></span>
                                    <span class="location"><?php echo esc_attr($enlighten_location); ?></span>
                                </div>
                            </div>
                          <?php } ?>
                      </div>
            <?php } ?>
            </div>
        </div>
        <?php
            $enlighten_alignment = get_theme_mod('enlighten_menu_alignment','center');
            $enlighten_position = get_theme_mod('enlighten_menu_style','top');
            if($enlighten_position == ''){$enlighten_position = 'top';}
         ?>
        <nav id="site-navigation" class="main-navigation <?php if($enlighten_alignment || $enlighten_position){echo esc_attr($enlighten_alignment.' '.$enlighten_position);} ?>" role="navigation">
            <div class="ak-container">
                <div class="mb-ham">
                    <span></span>
                    <span></span>
                    <span></span>
                </div>
                <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_id' => 'primary-menu', 'container_class' => 'menu-menu-1-container mmenu-wrapper' ) ); ?>
            </div>
        </nav><!-- #site-navigation -->

        <?php 
            if(is_home() || is_front_page()){
                $enlighten_slider_enable = get_theme_mod('enlighten_enable_slider');
                if($enlighten_slider_enable){
                    do_action('enlighten_header_slider_action');
                } 
        } ?>
    </header><!-- #masthead -->

    <!-- Header Banner -->
    <?php do_action('enlighten_header_banner'); ?>

    <div id="content" class="site-content">
1

I understand that parent theme updates are not supposed to affect child theme modifications, but does that mean that if I have header.php in my child theme (wp-content/themes/enlighten-child/header.php), then no parent theme updates to the header.php will affect my website?

WordPress will always load the Child Theme's header.php on your site, so theoretically no, it won't affect you. However there's no guarantee that the parent theme won't change something in its header.php and then make changes to other files that depend on that change. If that change isn't reflected in your child theme's header then there could be issues.

For example, say the parent theme releases an update that adds a <div> element in header.php which gets closed, with </div>, in footer.php. If you only have a copy of header.php in your child theme then the parent theme's footer.php will have a closing tag for an element that's not being opened.

That's mostly just a hypothetical example of something that could happen, but because of that I suggest checking the release notes for the parent theme before each update to keep an eye out for any changes that could affect child themes.

Does the same apply to modifying widget PHP code?

Depends on the parent theme and what widget you're talking about. WordPress will only automatically handle child theme inheritance of templates that are part of the template hierarchy as well as a couple of others, like header.php, footer.php, comments.php and searchform.php.

All other code, in functions or template files, requires that the parent theme explicitly support child theming. You will need to ask the parent theme's developer what is child theme-able if you're not sure.

If either of the above answers are “yes”, how can I easily benefit from other enhancements/fixes that come with parent theme updates to the PHP files with the same names as those I’ve modified, without losing my changes? I guess I’m wanting to have my changes merged with those made by the theme vendor, but I expect that's probably too much to ask.

If you want to adopt any changes the parent theme makes to files that you have replaced in the child theme (such as the new div example above) you will need to manually incorporate those yourself by copying the new bits into your child theme files, or redoing them.

After activating the child theme, I noticed that some of the customisations I’d made to the parent theme disappeared. (When I say “customizations”, I mean changes made via Appearance > Customise > Header Setting > Header Info Section, for example, not changes to PHP code.) Is that normal and what parent theme customizations can I expect to lose when creating/activating a child theme?

Theme mods, which are what changes made in the Customiser are typically saved as, are stored against the active theme regardless of whether it is a parent or child theme. Exactly what customisations you will lose when switching to a child theme depends on the parent theme.

It is theoretically possible to copy the theme mods from a parent theme to a child theme by modifying the database directly though. See the answer to this question for a method for doing this.

I'm currently working on a project where I want customisations made on one child theme to also be applied to other child themes of the same parent when switching themes. This requires me to save customisations as options, rather than theme mods. So if this is what you want it requires the parent theme to work the same way.

I understand that updating a parent theme will not touch the child theme files, but if I’m not even using a child theme, will updating the theme via WordPress always replace the header.php file, or will it only be replaced if the file has changed since what it was when it came out when the currently installed version was distributed?

All files within a theme will be replaced when the theme is updated, whether or not they were actually changed in the new version. Any new files will also be removed, and any removed files will be re-added. WordPress does not support 'delta updates'. This is why you will see people being very adamant about not modifying parent themes.

  • Thank you so much for such an impressive and comprehensive answer, Jacob. You seem to have understood exactly what I mean, and have covered it with a good level of detail. Many thanks from over the ditch, and go to the top of the WP class (if you aren't already there). – Terry May 17 '18 at 0:16

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.