A WordPress theme can be enhanced with additional features and this may sometimes require hard-coding the theme files. Hard-coding a parent theme file may result in a loss of all the custom code as the files are overwritten with new version during a theme update.

A child theme is designed to store the theme files without losing the modifications during the update process. It runs on a parent theme but when a copy of the parent theme file is added to the child theme directory, automatically WordPress gives priority to the files in the child theme folder.

Usage example:

Ok! Let’s try to add a custom tag in the head section of the header.php file.

If we hard-code the header.php file in the parent theme directory. When a theme update is released the theme files will be overwritten resulting in a total loss of all the modified files.

To display a tag in the head section of your site we can copy the header.php file from the main theme wp-content\themes\enfold into the child theme directory wp-content\themes\enfold-child and modify the head section.

Leave a Reply

Your email address will not be published.