I. WordPress Child Theme, step by step

First, locate your /wp-content/themes directory then create sub-directory for the new child theme e.g. twentynineteen-child.

Then create files inside this sub-directory:

  • functions.php
  • style.css
  • script.js
  • screenshot.png

Functions.php

<?php
function my_theme_enqueue(){
     $parent_style = 'twentynineteen-style';
     wp_enqueue_style(
          $parent_style, 
          get_template_directory_uri() . '/style.css');
     wp_enqueue_style(
          'child-style',
          get_stylesheet_directory_uri() . '/style.css',
          array($parent_style),
           wp_get_theme()->get('Version'));

     //if child theme also has custom script, load it too here.
     //last parameter is false to load script in <head> else to <body>.
     wp_enqueue_script(
          'child-script',
          get_stylesheet_directory_uri() . '/script.js',
          array(),
          '1.0',
          true);
} 
add_action('wp_enqueue_scripts', 'my_theme_enqueue');

Style.css

/*
     Theme Name: Twenty Nineteen Child
     Theme URI: http://oldhendra.c1.biz
     Description: Twenty Nineteen Child Theme
     Author: oldhendra
     Author URI: http://oldhendra.c1.biz
     Template: twentynineteen
     Version: 1.0
     License: GNU General Public License v2 or later
     License URI: http://www.gnu.org/licenses/gpl-2.0.html
     Text Domain: twentynineteen-child
     Tags: one-column, two-columns, right-sidebar, flexible-header, accessibility-ready, custom-colors, custom-header, custom-menu, custom-logo, editor-style, featured-images, footer-widgets, post-formats, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready
 */
     body{
         color: green;
     }

Script.js

'use strict';
 +function(){
     console.log('twenty nineteen child js loaded.');
 }();//end of unanonymous, self-run, privatize function

Screenshot.png

This file is just a regular, 1200 x 900 px image:

twenty nineteen child (theme)

Next step, login to your WordPress Dashboard and go into Appearance > Themes menu to find your new Twenty Nineteen Child enlisted there. Click on this theme to activate it…

Done 🙂

Leave a comment

Your email address will not be published.