FrugalWebGuy is Merging with Michael Mann Web Design under the new Title of I Do Web Work

Child Theme Development – functions.php

Video Available (Signup to Access - Members Only)

For a child theme, only one file is absolutely required, style.css. As discussed in the style.css child theme training, the use of a @import option is not the best option. This is where the functions.php file comes in handy. We can add a small block of code which will grab the style.css from the parent theme and enqueue it for use. This is preferred method for WordPress and offers a speed improvement over using the @import method. In addition to the speed improvement, your site will be able to rank higher on Google's Page Speed and Yahoo's YSlow services. These services are used by the respective search engine when ranking your site.

Now On to The Code

<?php
// Faster than @import
add_action( 'wp_enqueue_scripts', 'my_child_theme_scripts' );
function my_child_theme_scripts() {
    wp_enqueue_style( 'parent-theme', get_template_directory_uri() . '/style.css' );
}
?>

Basically, what this code does is add in the parent's stylesheet. That get_template_directory() gets us the url of the parent's theme and the style.css add the default style.css file to that address.

Load Order

The load order of theme files is important to remember. As you will learn in Part 3 of this series, most parent theme files are replaceable with a same named file in the child theme. The one exception is the functions.php file. The child theme's functions.php can be used to remove items added by the parent theme or add to the functionality of the parent.

This Training Series

Part I: Child Theme Development - style.css
Part II: Child Theme Development - functions.php
Part III: Child Theme Development - Custom Meta Box