Child themes are essential to anyone who wants to modify a WordPress theme. If you do not create a Child Theme and instead modify the original theme, any future updates to that theme could completely overwrite your edits. Fortunately, creating a Child Theme is not overly difficult and is extremely flexible. You can keep things as simple as adding CSS to your Child Theme's style sheet or as advanced as adding templates or functions your Child Theme. In this example we'll keep it simple with some basic CSS changes to customize the look of our Site Title and Site Description.
In this example, we'll be inserting the following code into the style.css file:
/*
Theme Name: Twenty Eleven Child
Theme URI: http://example.com/twenty-eleven-child/
Description: Twenty Eleven Child Theme
Author: Someone
Author URI: http://example.com
Template: twentyeleven
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: twenty-eleven-child
*/
This entire block of code is simply used to provide information about the child theme.
Next, you will use the same steps to edit the functions.php file and insert the following code:
<?php
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_uri(), array( 'parent-style' ) );
}
This is the last step for creating the child theme. As per WordPress codex, the code in the functions.php enables you to enqueue the parent theme stylesheets. NOTE: Using "@import" is not considered the best practice for importing a parent theme stylesheet. For more details, please see WordPress Codex: child themes.
#site-title,
#site-description {
font-family: Georgia, "Times New Roman", Times, serif;
font-weight:bold;
text-align:center;
margin:10px auto;
color: #e56c07
}
#site-title a {
color: #0c8fbe
}
Here's the updated site with the new styles in action:
There are many things you can do with a Child Theme. If you would like to go further in depth with Child Themes, please see the WordPress Codex on Child Themes.
Email: | support@WebHostingHub.com | Ticket: | Submit a Support Ticket |
---|---|---|---|
Call: |
877-595-4HUB (4482) 757-416-6627 (Intl.) |
Chat: | Click To Chat Now |
We value your feedback!
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
new! - Enter your name and email address above and we will post your feedback in the comments on this page!