Note that the wp-content > uploads folder does not appear until images are first uploaded.
At the very minimum, a WordPress Theme consists of at least two files, plus an optional 1200×900 image to suggest the theme’s design :
A child theme can be even simpler because it inherits the functionality and styling of
a parent theme. It can be done with one file that imports the parent style.css.
But the current best practice is to use a functions.php that enqueues the parent style.css file:
Child themes are the best way to make major modifications to an existing theme. *
* minor modifications to style can be done using the theme’s Customize feature.
On the left is an example of posts using the twentytwelve theme.
The two post on the right are the same posts using a child theme. The style is that of twentythirteen, but the sequence of elements still follows twentytwelve’s template.
The above example was created using a child theme which consists of nothing more than a style.css file in a folder named twentytwelve-child. The code looks like this:
It is the simplest code for a child theme (although in this example we changed the path of the style.css file).
In the code after the import of the style.css file, you can add your own css:
Next we’ll look at more complicated code.
Theme Name: Twenty Sixteen – Child
Enqueue the parent and child theme stylesheets because using @import increases the amount of time it takes style sheets to load.
add a wp_enqueue_scripts action in a function.php file
Setting ‘parent-style’ as a dependency will ensure that the child theme stylesheet loads after it.
Including the child theme version number ensures that you can bust cache also for the child theme. See a more detailed discussion on Stack Exchange:
The complete (recommended) example becomes:
where |parent-style| is the same |$handle| used in the parent theme when it registers its stylesheet.
For example, if the parent theme is twentyfifteen, by looking in its functions.php
for its |wp_enqueue_style()| call, you can see the tag it uses there is |’twentyfifteen-style’|. In your child code, replace the instance of |’parent-style’| with |’twentyfifteen-style’|, like so:
$parent_style = ‘twentyfifteen-style’;
Failure to use the proper tag will result in a CSS file needlessly being
loaded twice. This will usually not affect the site appearance, but it’s
inefficient and extends your page’s loading time.
*Note:* You may need to re-save your menu (Appearance > Menus, or
Appearance > Customize > Menus) and theme options (including background
and header images) after activating the child theme.
If you want to change more than just the stylesheet, your child theme
can override any file in the parent theme: simply include a file of the
same name in the child theme directory, and it will override the
equivalent file in the parent theme directory when your site loads.
Unlike the style.css file, the functions.php file of a child theme does not
override (cascade) its counterpart from the parent. Instead, it is loaded in
addition to the parent’s functions.php. Specifically, right before the parent’s file.
The fact that a child theme’s functions.php file
is loaded first means that you can make the user functions of your theme
pluggable, i.e., replaceable by a child theme by declaring them
In that way, a child theme can replace a PHP function of the parent by
simply declaring it beforehand.
When you need to include files that reside within your child theme’s
directory structure, you can use get_stylesheet_directory().
It points to your child theme’s directory because that is where your style.css resides.
A child theme inherits post formats as defined by the parent theme.
When creating child themes, be aware that using
add_theme_support(‘post-formats’) will override the formats defined
by the parent theme, not add to it.
add_theme_support( ‘post-formats’, array( ‘aside’, ‘gallery’ ) );
add_theme_support( ‘post-formats’, array( ‘aside’, ‘link’, ‘gallery’, ‘status’, ‘quote’, ‘image’ ) );
add_theme_support( ‘post-formats’, array( ‘aside’, ‘image’, ‘link’, ‘quote’, ‘status’ ) );
add_theme_support( ‘post-formats’, array( ‘aside’, ‘audio’, ‘chat’, ‘gallery’, ‘image’, ‘link’, ‘quote’, ‘status’, ‘video’ ) );
add_theme_support( ‘post-formats’, array( ‘aside’, ‘image’, ‘video’, ‘audio’, ‘quote’, ‘link’, ‘gallery’, ) );
add_theme_support( ‘post-formats’, array( ‘aside’, ‘image’, ‘video’, ‘quote’, ‘link’, ‘gallery’, ‘status’, ‘audio’, ‘chat’ ) );
add_theme_support( ‘post-formats’, array( ‘aside’, ‘image’, ‘video’, ‘quote’, ‘link’, ‘gallery’, ‘status’, ‘audio’, ‘chat’, ) );
add_theme_support( ‘post-formats’, array( ‘aside’, ‘image’, ‘video’, ‘quote’, ‘link’, ‘gallery’, ‘audio’,) );
To support RTL languages, add an rtl.css file containing simple code to your child theme.
Theme Name: Twenty Fourteen Child
The rtl.css is only loaded if is_rtl() returns true.
It’s recommended to add the rtl.css file to your child theme even if the parent theme has no rtl.css file.
All strings that use “my-child-theme” textdomain will be
esc_html_e displays translated text that has been escaped for safe use in HTML output.
The translation files must reside in languages directory.