Child themes
-
Hi all,
I am not sure if I am doing this correctly. I am using Twenty Sixteen and have created a child them using One-Click Child Theme. All my changes are done on the active child theme I have not done anything else such as copying style.css or any other files to the child theme directory. I have been adding the style changes via Simple CSS plugin. After reading how to add child themes I am a bit confused. Is there anything else I need to do to ensure I won’t lose my changes if the theme is updated?
Regards,
Steve
-
Is there anything else I need to do to ensure I won’t lose my changes if the theme is updated?
A Child Theme does exactly that – ensures that you won’t lose any changes if and when the parent theme is updated.
Did you enqueue your parent and child themes into your child theme?
Your child theme functions.php should have code in it that looks similar, but not exactly, like this:
<?php function theme_enqueue_styles() { $parent_style = 'parent-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 ) ); } add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );All the code that you put into the Simple CSS plugin can be put into your Child Theme’s CSS (style.css) and you could eliminate the Simple CSS plugin.
You could even download your Child Theme to your computer to keep a copy safe.
I did not enqueue the themes.
The child functions.php file is as below. It would seem the child theme generator plugin has done the enqueue process.
<?php
//
// Recommended way to include parent theme styles.
// (Please see http://codex.ww.wp.xz.cn/Child_Themes#How_to_Create_a_Child_Theme)
//
add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
function theme_enqueue_styles() {
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’)
);
}
//
// Your code goes below
//No, this is just the template, which is also the code I posted, which you have to fill in for it to work.
“parent-style” and “child-style” have to be set to your parent theme name and child theme name as per the link: http://codex.ww.wp.xz.cn/Child_Themes#How_to_Create_a_Child_ThemeDo I replace all parent-style/child style text with the them names or only the text in brackets?
This is now the functions.php file in my child them. Is this correct?
The child styles.css file still has no code in it.
<?php
//
// Recommended way to include parent theme styles.
// (Please see http://codex.ww.wp.xz.cn/Child_Themes#How_to_Create_a_Child_Theme)
//
add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
function theme_enqueue_styles() {
wp_enqueue_style( ‘Twenty Sixteen’, get_template_directory_uri() . ‘/style.css’ );
wp_enqueue_style( ‘Twenty Sixteen Child’,
get_stylesheet_directory_uri() . ‘/style.css’,
array(‘Twenty Sixteen’)
);
}
//
// Your code goes below
//Send me your parent theme’s name and your child theme’s name.
These are not the names you see when in in Appearance > Themes.Go to Appearance > Editor.
Select your parent theme from the drop-down (top-right).
It should default to the parent theme’s CSS.
At the top of the CSS where all the asterix are (***), there is a something labelled “Text domain”. Copy that version of your parent theme name and post it here.Repeat the above for your child theme.
Parent theme is twentysixteen
There is no text domain for the child theme, style.css code is below/*
Theme Name: Twenty Sixteen Child
Description: Child theme for Twenty Sixteen, created from partially edited Twenty Sixteen theme
Author: Castle Images Admin
Template: twentysixteen(optional values you can add: Theme URI, Author URI, Version, License, License URI, Tags, Text Domain)
*/Is what you posted above everything in your child theme’s functions.php?
This is what you posted
<?php // // Recommended way to include parent theme styles. // (Please see http://codex.ww.wp.xz.cn/Child_Themes#How_to_Create_a_Child_Theme) // add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { wp_enqueue_style( 'Twenty Sixteen', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'Twenty Sixteen Child', get_stylesheet_directory_uri() . '/style.css', array('Twenty Sixteen') ); } // // Your code goes below //Yes
Then, delete everything (…yes, everything) π …in the child theme functions.php file and paste the following in it – exactly as it is…
with NO space underneath the last line of code!<?php function twentysixteenchild_enqueue_styles() { $parent_style = 'twentysixteen'; wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'twentysixteen-child', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ) ); } add_action( 'wp_enqueue_scripts', 'twentysixteenchild_enqueue_styles' );Now, any styling you put into the child style.css will over-ride the parent style.css.
Simmilar with the child functions.php. Any function code you may put in there will be in addition to, or alter, the parent function.php.Thank you very much. What country are you in?
I imagine then that the changes I have added via simple css would have gone to the parent?
Thank you very much. What country are you in?
Ottawa, Onatrio, Canada
I imagine then that the changes I have added via simple css would have gone to the parent?
A Custom CSS plugin works similar to a child theme, in that it is loaded after the main (parent) theme and therefore alters the main theme – but you do not need both a Custom CSS plugin and a child theme.
A child theme is better as you can periodically download it to your computer, thereby saving all your changes, whereas the plugin is not downloadable, and sometimes can become in conflict with other plugins, though rarely.
Thanks again. Rather early in the moring isn’t it? You need some sleep.
If you follow tennis, your countryman did well last night. I am a tennis junkie as well as an IT nerd, but no experience in web coding!
Forgot to add, it is all working well. Checked to make sure by deleting the custom changes and adding them in to the child styles file, checking each change.
The topic ‘Child themes’ is closed to new replies.
