{"id":4227,"date":"2022-04-26T13:27:26","date_gmt":"2022-04-26T10:27:26","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=4227"},"modified":"2022-09-01T11:32:16","modified_gmt":"2022-09-01T08:32:16","slug":"how-to-create-a-child-theme-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/how-to-create-a-child-theme-in-wordpress\/","title":{"rendered":"How to Create a Child Theme in WordPress"},"content":{"rendered":"\n<p><span style=\"font-weight: 400;\">With <\/span><b>over nine thousand themes<\/b><span style=\"font-weight: 400;\"> in the <\/span><b>official WordPress repository<\/b><span style=\"font-weight: 400;\"> and <\/span><b>countless others<\/b><span style=\"font-weight: 400;\"> available on third-party websites, it&#8217;s safe to say that you&#8217;re somewhat spoiled for choice when it comes to <\/span><a href=\"https:\/\/wordpress.org\/themes\/\"><b>picking a design for your WP project<\/b><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Sometimes, however, website owners find out that off-the-shelf themes can&#8217;t give them the appearance they&#8217;re after. If you find yourself in a similar position, you&#8217;ll want to take an existing theme and <\/span><b>add some custom code to it<\/b><span style=\"font-weight: 400;\">. However, before you do that, you&#8217;ll need to <\/span><b>create a child theme<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Let&#8217;s see what this means.<\/span><b><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>What Is a Parent Theme?<\/b><b><\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">We&#8217;ll start by clearing up some of the principal concepts behind WordPress themes. First, we&#8217;ll look at <\/span><b>parent themes<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><b>Any standard WordPress theme<\/b><span style=\"font-weight: 400;\"> can be a parent theme, regardless of whether you download it from the official repository or from a third-party website. Here&#8217;s how it works.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">A WordPress theme itself is a collection of files that determine your website&#8217;s look. Every theme has its own directory inside the <\/span><b><i>\/wp-content\/themes <\/i><\/b><span style=\"font-weight: 400;\">subfolder of your site&#8217;s document root. A database entry tells <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/what-is-wordpress-how-does-it-work\/\"><b>WordPress<\/b><\/a> <span style=\"font-weight: 400;\">which of these folders belongs to the active theme, so the content management system knows which <\/span><b>CSS stylesheets, <\/b><a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-change-the-php-version-for-your-site\/\"><b>PHP<\/b><\/a><b>, JavaScript, and media files<\/b><span style=\"font-weight: 400;\"> it needs to use to render the site&#8217;s appearance. If you want to modify the design to your specific needs, you&#8217;ll need to add your custom code to these files.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The thing is, <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/best-wordpress-themes\/\"><b>WordPress themes<\/b><\/a> <b>receive regular updates<\/b><span style=\"font-weight: 400;\">, which you must install as soon as they&#8217;re available. In addition to bringing new features that improve your website&#8217;s user experience, these updates also carry <\/span><b>vulnerability patches critical to your site&#8217;s security<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">When you update a theme, you effectively download new versions of the theme&#8217;s files, <\/span><b>overwriting the old ones in the process<\/b><span style=\"font-weight: 400;\">. In other words, if you update a theme you&#8217;ve customized, <\/span><b>all your work will be lost<\/b><span style=\"font-weight: 400;\">.<\/span><b><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>What is a Child Theme?<\/b><b><\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">A child theme works in tandem with the parent theme to allow you to <\/span><b>keep your custom code without preventing you from installing critical updates<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">In some ways, it acts as a standalone theme in that it has its own folder inside the <\/span><b><i>\/wp-content\/themes<\/i><\/b><span style=\"font-weight: 400;\"> directory and is available on the <\/span><b>Appearance <\/b><span style=\"font-weight: 400;\">&gt; <\/span><b>Themes<\/b><span style=\"font-weight: 400;\"> page inside the <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/navigating-your-wordpress-dashboard\/\"><b>WordPress dashboard<\/b><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">However, instead of containing all the templates that determine your site&#8217;s look and functionality, <\/span><b>it only holds your <\/b><a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-customize-your-wordpress-theme\/\"><b>custom design elements<\/b><\/a><span style=\"font-weight: 400;\">. In fact, if your modifications are limited to the site&#8217;s typography, your child theme will consist <\/span><b>of two files only<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">WordPress will read the custom code from these files, and for the rest of your site&#8217;s look, it will <\/span><b>fall back to the parent theme<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><b>You can update the parent theme<\/b><span style=\"font-weight: 400;\"> whenever there&#8217;s a new version without touching the child theme and losing your custom look.<\/span><b><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>How to Create a Child Theme<\/b><b><\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">There are a couple of ways of setting up a child theme folder \u2013 <\/span><b>manually or with a plugin<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Obviously, the second method is <\/span><b>preferred by less experienced users<\/b><span style=\"font-weight: 400;\">. There&#8217;s certainly no shortage of options. The &#8220;child theme&#8221; term returns quite a few search results in the <\/span><a href=\"https:\/\/wordpress.org\/plugins\/\"><b>WordPress official plugin repository<\/b><\/a><span style=\"font-weight: 400;\">, with each add-on offering a broad range of options and features.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"533\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/6-1024x533.png\" alt=\"How to Create a Child Theme in WordPress, How to Create a Child Theme\" class=\"wp-image-4229\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/6-1024x533.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/6-300x156.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/6-768x400.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/6-1536x800.png 1536w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/6.png 1734w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">The steps you&#8217;ll need to take to set up a child theme via a plugin depend on the plugin itself. However, it&#8217;s fair to say that you&#8217;re <\/span><b>unlikely to run into any serious problems<\/b><span style=\"font-weight: 400;\">. Most plugin vendors try to make their products&#8217; interface as intuitive as possible, and there are often quite a few tooltips telling you what each of the buttons does.<\/span> <span style=\"font-weight: 400;\">In some cases, you can rely on technical support from the plugin developer, as well.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The manual creation of a child theme is a bit more complex. However, it could help you better understand <\/span><b>how themes work in general<\/b><span style=\"font-weight: 400;\">, which, in turn, could be useful later when you&#8217;re customizing your website&#8217;s look.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">If you&#8217;re doing it for the first time, using <\/span><b>a staging environment or a test installation<\/b><span style=\"font-weight: 400;\"> might not be a bad call. You&#8217;re unlikely to do any serious damage to the site, but you can never be too careful. What&#8217;s more, you&#8217;ll want to make sure everything works <\/span><b>before pushing the changes to production<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">To manually set up a new child theme in WordPress, you need to <\/span><b>create a new folder and set up a couple of files<\/b><span style=\"font-weight: 400;\">. Those comfortable working with the command-line can use <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/what-is-ssh-and-how-to-use-it\/\"><b>SSH<\/b><\/a><span style=\"font-weight: 400;\">, though most people will prefer doing it via the control panel&#8217;s file manager. For our example, we&#8217;ll create a child theme of <\/span><b>Twenty Twenty-Two<\/b><span style=\"font-weight: 400;\"> \u2013 the default WordPress theme at the time of writing. Let&#8217;s see the exact steps:<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><b>1. Navigate to <\/b><b><i>\/wp-content\/themes<\/i><\/b><b> and set up the child theme&#8217;s new folder<\/b><b><br><\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">If your site is on your account&#8217;s main domain, its document root folder should be public_html (unless you&#8217;ve changed it yourself). Open it, and go to <\/span><i><span style=\"font-weight: 400;\">wp-content\/themes<\/span><\/i><span style=\"font-weight: 400;\">. You&#8217;ll see the folders of the themes currently installed on your website.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"376\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/1-1024x376.png\" alt=\"How to Create a Child Theme in WordPress, 1. Navigate to \/wp-content\/themes and set up the child theme&#8217;s new folder\" class=\"wp-image-4230\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/1-1024x376.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/1-300x110.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/1-768x282.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/1-1536x564.png 1536w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/1.png 1918w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">To set up a new one, you&#8217;ll need to create a folder for it. Although you can use a random name, it&#8217;s considered best practice to append &#8220;<\/span><i><span style=\"font-weight: 400;\">&#8211;<\/span><\/i><span style=\"font-weight: 400;\">child&#8221; to the name of the parent theme. In our case, we&#8217;ll name the folder &#8220;<\/span><i><span style=\"font-weight: 400;\">twentytwentytwo-child<\/span><\/i><span style=\"font-weight: 400;\">.&#8221;<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"757\" height=\"461\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/2.png\" alt=\"How to Create a Child Theme in WordPress, 1. Navigate to \/wp-content\/themes and set up the child theme&#8217;s new folder 2\" class=\"wp-image-4231\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/2.png 757w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/2-300x183.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\"><b>2. Set up a stylesheet \u2013 style.css<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">The child theme&#8217;s main stylesheet, style.css, usually carries<\/span><b> the bulk of the customizations<\/b><span style=\"font-weight: 400;\">. Using your File Manager, you can create it straight on the server via <\/span><b>New <\/b><span style=\"font-weight: 400;\">&gt; <\/span><b>New File<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"194\" height=\"181\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/3.png\" alt=\"How to Create a Child Theme in WordPress, 2. Set up a stylesheet \u2013 style.css\" class=\"wp-image-4232\"\/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\"><b>3. Enqueue your stylesheet<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">In addition to containing your custom typography, the style.css file also <\/span><b>points WordPress to the parent theme<\/b><span style=\"font-weight: 400;\">. You need a couple of main lines in the style.css file to set up a child theme \u2013 <\/span><b>theme name and template<\/b><span style=\"font-weight: 400;\">. Here&#8217;s what it should look like:<\/span><\/p>\n\n\n\n<p class=\"alert-orange\"><b><i>\/*\n<br>Theme Name: Twenty Twenty-Two\n<br>Template: [the name of the parent theme]\n<br>*\/<\/i><\/b><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/4.png\" alt=\"How to Create a Child Theme in WordPress, 3. Enqueue your stylesheet\" class=\"wp-image-4233\" width=\"786\" height=\"228\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/4.png 786w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/4-300x87.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/4-768x223.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"alert-blue\"><b>NOTE: <\/b><span style=\"font-weight: 400;\">You need the name of the parent theme&#8217;s folder in <\/span><i><span style=\"font-weight: 400;\">wp-content\/themes<\/span><\/i><span style=\"font-weight: 400;\">, not the name you see in the WP dashboard.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Don&#8217;t forget to add <\/span><b>\/* <\/b><span style=\"font-weight: 400;\">at the beginning and <\/span><b>*\/ <\/b><span style=\"font-weight: 400;\">at the end of this section.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">If you want, you can add additional information. If you&#8217;re distributing the theme, for example, you can enter the author, the version, some contact details, etc.<\/span><\/p>\n\n\n\n<p><b>Save and close<\/b><span style=\"font-weight: 400;\"> the file when you&#8217;re done.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><b>4. Create a functions.php file<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">If you look inside the WP dashboard, you&#8217;ll see that the child theme is already listed on the <\/span><b>Appearance <\/b><span style=\"font-weight: 400;\">&gt; <\/span><b>Themes <\/b><span style=\"font-weight: 400;\">page. What you need to do now is connect it to the parent theme. To do that, you need to create a second file called <\/span><b><i>functions.php<\/i><\/b><span style=\"font-weight: 400;\"> in the child theme folder.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"599\" height=\"199\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/5.png\" alt=\"How to Create a Child Theme in WordPress, 4. Create a functions.php file\" class=\"wp-image-4228\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/5.png 599w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/04\/5-300x100.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\"><b>5. Connect the child theme to the parent one<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">Open the <\/span><i><span style=\"font-weight: 400;\">functions.php <\/span><\/i><span style=\"font-weight: 400;\">file and paste the code you see below.<\/span><\/p>\n\n\n\n<p class=\"alert-orange\"><b><i>&lt;?php\n<br>add_action( &#8216;wp_enqueue_scripts&#8217;, &#8216;enqueue_parent_styles&#8217; );\n<br>function enqueue_parent_styles() {\n<br>wp_enqueue_style( &#8216;parent-style&#8217;, get_template_directory_uri().&#8217;\/style.css&#8217; );\n<br>}\n<br>?&gt;<\/i><\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The code above means that the child theme inherits the parent theme&#8217;s style and functionality while also <\/span><b>retaining the customizations you add to it<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><b>6. Activate the theme<\/b><\/h3>\n\n\n\n<p><span style=\"font-weight: 400;\">&nbsp;Finally, it&#8217;s time to go back to the WP dashboard and activate the new child theme from the <\/span><b>Appearance <\/b><span style=\"font-weight: 400;\">&gt; <\/span><b>Themes <\/b><span style=\"font-weight: 400;\">page.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With over nine thousand themes in the official WordPress repository and countless others available on third-party websites, it&#8217;s safe to say that you&#8217;re somewhat spoiled for choice when it comes to picking a design for your WP project. Sometimes, however, website owners find out that off-the-shelf themes can&#8217;t give them the appearance they&#8217;re after. If [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-4227","post","type-post","status-publish","format-standard","hentry","category-web-hosting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/4227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/comments?post=4227"}],"version-history":[{"count":10,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/4227\/revisions"}],"predecessor-version":[{"id":5062,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/4227\/revisions\/5062"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=4227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=4227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=4227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}