{"id":2916,"date":"2015-03-31T17:24:05","date_gmt":"2015-03-31T21:24:05","guid":{"rendered":"http:\/\/teamtutorials.com\/?p=2916"},"modified":"2015-07-12T21:23:59","modified_gmt":"2015-07-13T01:23:59","slug":"using-wordpress-child-themes","status":"publish","type":"post","link":"https:\/\/teamtutorials.com\/web-development-tutorials\/wordpress-tutorials\/using-wordpress-child-themes","title":{"rendered":"Using WordPress Child Themes"},"content":{"rendered":"
There are tons of quality WordPress themes out there. You\u00a0found the perfect one for your site, almost.\u00a0Everything looks good at first then you decide you need a few little tweaks to the theme code to really fit your needs. Stop modifying the theme directly.<\/strong> Start using WordPress Child Themes. If you aren’t familiar with child themes it’s time to learn about them.<\/p>\n Child themes in WordPress allow you to inherit the code from a theme template. You can override basically anything you would (PHP, HTML, CSS, JavaScript) as if you were modifying the parent theme directly. However, the benefit of using child themes is that it keeps the parent\u00a0theme untouched. If you were to modify the theme directly and then update that theme using WordPress’ update feature you would lose all of your customizations. With child themes you won’t lose any of your changes when you update the parent theme as your changes are in their own directory. Plus child themes are so easy there really isn’t an excuse not to use them.<\/strong><\/p>\n If you’ve ever tried to create a WordPress theme on your own you already know most of what it takes to create a child theme. If you haven’t dug into creating your own theme yet don’t worry. It’s very simple to create a child theme but it does require some knowledge of HTML, CSS, and PHP. Creating a child theme is a great way to learn about WordPress if you need to brush up on some of those skills.<\/p>\n I’m going to show you how to create a child theme based on the new WordPress default theme Twenty Fifteen<\/a>. First navigate to the theme directory of you install which is probably something like \/wp-content\/themes\/<\/p>\n <\/a><\/p>\n <\/p>\n Next create a new folder for your child theme. It’s not required to use this format but I general name the folder {theme name}-child. So in this case the folder will be called twentyfifteen-child.<\/p>\n There are two requirements for child themes. The first is a\u00a0style.css file\u00a0and the second is a functions.php file. Next open your favorite text editor (I’ve been using Atom<\/a> lately). We’re going to create the style.css. You can find an example of this file on the WordPress codex.<\/a><\/p>\n Paste the following into your text editor. You should fill in all of the fields but the most important fields are Theme Name (the name you will see in the WordPress admin) and the template section. The template tells WordPress where to go to get the original theme’s file so you want to make sure this name matches the parent theme. I did this for my personal site <\/a>and had problems with the name’s not matching so be sure to check it.<\/p>\n You can add your name and update the urls then save this inside the twentyfifteen-child directory as style.css<\/strong>. Then you’ll want to create another new file in your editor. Paste the following code:<\/p>\n You can save this file in the twentyfifteen-child directory as functions.php<\/strong>. This is all the is technically necessary. However, the WordPress Codex also mentions that you may want to make sure the parent theme is loaded first by making the child them a dependent in the functions.php file. To do that you would updated the functions.php file to look like this:<\/p>\n Now your new child theme directory should look like this<\/p>\n <\/a><\/p>\n Now you can enable the theme in the WordPress -> Appearance section by clicking the activate button on the new child theme.<\/p>\n <\/a><\/p>\n <\/p>\n Once activate your child theme behaves like any other WordPress theme. You can change the look using the built in customizer. You can add and edit widget. Now you can override any of the core files. For example if I wanted to change the background of this white sidebar to a different color.<\/p>\n <\/p>\n If I wanted to make it red I would use the browser inspection tool to find out what css I want to override. Keep in mind you can actually change this color using the built in customizer but I’m doing it using CSS as an example.<\/p>\n Using the inspector I see that the div I want to override has an ID of #sidebar<\/p>\n <\/a><\/p>\n Then I would open the style.css in my child theme and add a new rule below the comments to make this red.<\/p>\n Which would then give you<\/p>\n <\/a><\/p>\n <\/p>\n As you can see the sidebar is now red because we updated our style.css<\/p>\n Now that I’ve showed you how to make a simple CSS change you may be wonder what else you can do. Well you can override any of the file from the original theme. Take a look in the original theme directory.<\/p>\n <\/a><\/p>\n You can copy any of those files over to your child theme directory and then start hacking away at the code. Want to do something special in the author bio simply copy the author-bio.php file. Want to change the footer? Copy the footer.php file to your child directory and make your change.<\/p>\n The only thing that I’ve seen go wrong is that you can update the parent theme and then things can end up breaking because you have an old version of a file that was updated in your child theme. To fix this you have to compare the new file with the one in your child theme and update accordingly. That’s still better than modifying the original theme because in that case you would lose all your changes.<\/p>\n Let me know if this post helped you out or if you have any other questions. If this post did benefit you please share.<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":" There are tons of quality WordPress themes out there. You\u00a0found the perfect one for your site, almost.\u00a0Everything looks good at first then you decide you need a few little tweaks to the theme code to really fit your needs. Stop modifying the theme directly. Start using WordPress Child Themes. If you aren’t familiar with child … Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[],"yoast_head":"\nWhat are WordPress Child Themes?<\/strong><\/h2>\n
How you can get started with WordPress Child Themes<\/h2>\n
\n<\/a><\/a><\/p>\n\r\n\/*\r\n Theme Name: Twenty Fifteen Child\r\n Theme URI: http:\/\/example.com\/twenty-fifteen-child\/\r\n Description: Twenty Fifteen Child Theme\r\n Author: John Ward\r\n Author URI: http:\/\/example.com\r\n Template: twentyfifteen\r\n Version: 1.0.0\r\n License: GNU General Public License v2 or later\r\n License URI: http:\/\/www.gnu.org\/licenses\/gpl-2.0.html\r\n Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready\r\n Text Domain: twenty-fifteen-child\r\n*\/\r\n<\/pre>\n
\r\nadd_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );\r\nfunction theme_enqueue_styles() {\r\n wp_enqueue_style( 'parent-style', get_template_directory_uri() . '\/style.css' );\r\n\r\n}\r\n<\/pre>\n
\r\nadd_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );\r\nfunction theme_enqueue_styles() {\r\n wp_enqueue_style( 'parent-style', get_template_directory_uri() . '\/style.css' );\r\n wp_enqueue_style( 'child-style',\r\n get_stylesheet_directory_uri() . '\/style.css',\r\n array('parent-style')\r\n );\r\n}\r\n<\/pre>\n
\n<\/a> <\/a><\/p>\n\r\n\/*\r\n Theme Name: Twenty Fifteen Child\r\n Theme URI: http:\/\/example.com\/twenty-fifteen-child\/\r\n Description: Twenty Fifteen Child Theme\r\n Author: John Ward\r\n Author URI: http:\/\/example.com\r\n Template: twentyfifteen\r\n Version: 1.0.0\r\n License: GNU General Public License v2 or later\r\n License URI: http:\/\/www.gnu.org\/licenses\/gpl-2.0.html\r\n Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready\r\n Text Domain: twenty-fifteen-child\r\n*\/\r\n#sidebar{ background:red;}\r\n<\/pre>\n
What else can you do with WordPress Child Themes?<\/h2>\n
What can go wrong?<\/h2>\n