WordPress Child Themes and the functions.php File - Montana Webmaster

WordPress Child Themes and the functions.php File

Introduction

When WordPres doesn’t work the way you want it to … the WordPress core also provides multiple ways for you to customize. All customizations should be done with plugins or in a parent/child theme, but not all customizations are the same.

Most of my theme customization work in WordPress has to do with layout, which are generally done with CSS coding, but sometimes, I need WordPress or a theme to function differently. Then I need to work in the functions.php file in the child theme.

A Child Theme Makes Sure Customizations aren’t Lost when you Update your WordPress Site

The purpose of the functions.php file in a theme and in a child theme is to allow a developer to add customizations to WordPress without having your customizations lost every time you update WordPress. If your customizations can be put somewhere that is separate from the WordPress core, your theme and your plugins, updating those files won’t overwrite the new work you have added. That is the purpose of a child theme.

The WordPress core is coded to to read and use your child theme when a viewer loads your site. If there is a child theme present, WordPress uses the child theme, instead of any duplicate functions in the core or the parent theme. That means that WordPress has to compare what is in the child theme with what is in the parent theme and only replace the code that is new … using code from the parent theme when it doesn’t exist in the child theme.

You can see how work for the CSS file if you go to View Source in your browser. These two lines of code from the <head> show that both the parent theme CSS file and the child theme CSS file are loaded:

  1. <link rel=’stylesheet’ id=’parent-style-css’ href=’https://montanawebmaster.com/wp-content/themes/kahuna/parent-style.min.css‘ media=’all’ />
  2. <link rel=’stylesheet’ id=’kahuna-main-css’ href=’https://montanawebmaster.com/wp-content/themes/MontanaWebmaster/kahuna-main.min.css‘ media=’all’ />

While the functions.php file works similarly, it doesn’t show in View Source because it does its job on the server and is not sent to the browser.

The functions.php file is PHP Code

PHP is a scripting language that runs on your web server (your web host). Much of WordPress is written in PHP. One example of something you might want to change in the PHP code, is to add in the results of a plugin in a place on your site that is not available in the Customizations tool.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.