dev-master
9999999-devA sample wordpress child theme skeleton to show how to implement a child theme with best practice.
MIT
The Requires
wordpress wordpress theme wordpress child theme child theme
A sample wordpress child theme skeleton to show how to implement a child theme with best practice.
This is to serve as a sample guide when I build child themes., (*1)
REF: - https://codex.wordpress.org/Child_Themes, (*2)
1) make sure to append the directory of the child theme with a '-child', (*3)
2) Should contain at least the following two files:, (*4)
- style.css - functions.php
3) The Stylesheet must begin with the header:, (*5)
/* Theme Name: Parent Name Child Theme URI: [] Description: A Child Theme of [Parent Name] Author: Wasseem Khayrattee Author URI: http://khayrattee.com Template: parent-folder-name # should corresponds to the directory name of the parent theme Version: a-number--optional General comments/License Statement if any. */
4) The functions.php is necessary to enqueue styles correctly. Do not use @import() in style.css to import parent stylesheet. This is bad practice. So use enqueue., (*6)
<?php function my_theme_enqueue_styles() { $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme. 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') ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); ?>
NOTE: - We can capitalise on the above by including a function FIRST in the child-theme so that it overrides its counterpart in the parent-theme, by declaring the function conditionally, (*7)
if ( ! function_exists( 'theme_special_nav' ) ) { function theme_special_nav() { // Do something. } }
Use this when we need to get the current directory path of the child theme. This is because Wordpress always give the path of the current active theme., (*8)
Example:, (*9)
require_once( get_stylesheet_directory() . '/my_included_file.php' );
For RTL support and localisation, see https://codex.wordpress.org/Child_Themes, (*10)
A sample wordpress child theme skeleton to show how to implement a child theme with best practice.
MIT
wordpress wordpress theme wordpress child theme child theme