Screenshot of some computer code
A screen shot of some random computer code.

Create a Child Theme

[Theme Feature – This isn’t a ‘feature’ really. It’s just something you should know about.]

Do you like the basics of the McGurk theme, but some things just annoy the crap out of you? Don’t like the font style? Want the author by-line placed somewhere else on the page?

Create a child theme and have it your own way!

In order to do this you will need two things:

  • A WordPress.org site.
    • Sorry, the free WordPress.com hosting does not have the facilities to create and upload your own child theme. Hey you get a boatload of cool stuff absolutely free. There’s gotta be limits.
  • Some knowledge of HTML, PHP, and CSS.
    • You don’t need to be a programming genius to make some basic changes, but if you don’t even know what these acronyms stand for then maybe a child theme isn’t for you.

A child theme needs two files minimum – style.css and functions.php. I’m going to give you the code you need to get started.

Below is the required header layout in the style.css file. Adjust the values to match your situation. The Template value is the name of the parent theme’s folder.

/*
 Theme Name: McGurk Child
 Theme URI: http://example.com/mcgurk-child/
 Description: McGurk Child Theme
 Author: John Doe
 Author URI: http://example.com
 Template: mcgurk
 Version: 1.0.2
 License: GNU General Public License v2 or later
 License URI: http://www.gnu.org/licenses/gpl-2.0.html
 Tags: responsive-layout, accessibility-ready
 Text Domain: mcgurk-child
*/

The functions.php file should include this code to properly enqueue the parent and child style sheets.

<?php
/**
 * Enqueue scripts and styles.
 */
function mcgurk_child_scripts()
{
 // Parent style sheet
 wp_register_style('mcgurk-main-style', get_template_directory_uri() . '/style.css');
 wp_enqueue_style('mcgurk-main-style');

 // Child style sheet
 wp_register_style('mcgurk-child-style', get_stylesheet_directory_uri() . '/style.css' , array(), '1.0.2', 'all');
 wp_enqueue_style('mcgurk-child-style');
}
add_action('wp_enqueue_scripts', 'mcgurk_child_scripts');
?>

That’s it. Happy coding.

Leave a Comment or Reply