{"id":149194,"date":"2015-04-30T23:12:54","date_gmt":"2015-04-30T21:12:54","guid":{"rendered":"http:\/\/www.elmastudio.de\/?p=149194"},"modified":"2018-03-13T03:02:03","modified_gmt":"2018-03-13T02:02:03","slug":"how-to-create-a-wordpress-child-theme-the-right-way","status":"publish","type":"post","link":"https:\/\/www.elmastudio.de\/en\/how-to-create-a-wordpress-child-theme-the-right-way\/","title":{"rendered":"How To Create A WordPress Child Theme &#8211; The Right Way"},"content":{"rendered":"<p>Since recently it was considered best practice in WordPress to include the parent stylesheet <em>(style.css)<\/em> with the <em>@import<\/em> rule  in your child theme&#8217;s style.css. However this technique got updated and now it&#8217;s best-practice to create a functions.php file for your child theme and use <em>wp_enqueue_style()<\/em> to include you parent theme stylesheet this way. I will show you shortly how this is done. <!--more--><\/p>\n<h4>Create your functions.php<\/h4>\n<p>So now next to your stylesheet <em>style.css<\/em> file and the <em>screenshot.png<\/em> file with your child themes preview image, you will also need to create a <em>functions.php<\/em> file for your child theme folder. You can use a text editor like Notepad++, Coda2 or Sublime Text to create your new <em>functions.php<\/em> file. The content of the file should include the following code snippet:<\/p>\n<p>[code]<br \/>\n&lt;?php<br \/>\n\/**<br \/>\n * Theme Name child theme functions and definitions<br \/>\n *\/<\/p>\n<p>\/*\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014*\/<br \/>\n\/* Include the parent theme style.css<br \/>\n\/*\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014*\/<\/p>\n<p>add_action( &#8216;wp_enqueue_scripts&#8217;, &#8216;theme_enqueue_styles&#8217; );<br \/>\nfunction theme_enqueue_styles() {<br \/>\n    wp_enqueue_style( &#8216;parent-style&#8217;, get_template_directory_uri() . &#8216;\/style.css&#8217; );<\/p>\n<p>}<br \/>\n[\/code]<\/p>\n<p>Now you included your parent theme&#8217;s stylesheet via the <em>functions.php<\/em> and you will only need your child theme&#8217;s  <em>style.css<\/em> file to add your own CSS to your theme. Your child theme&#8217;s <em>style.css<\/em> file should start like this:<\/p>\n<p>[code]<br \/>\n\/*<br \/>\n Theme Name: Theme Name Child<br \/>\n Theme URI:<br \/>\n Description: Theme Name Child Theme<br \/>\n Author: Your Name<br \/>\n Author URI: http:\/\/www.yourdomain.com\/<br \/>\n Template: yourparentthemetextdomain<br \/>\n Version: 1.0<br \/>\n License: GNU General Public License v2 or later<br \/>\n License URI: http:\/\/www.gnu.org\/licenses\/gpl-2.0.html<br \/>\n Tags: Theme Name Child Theme<br \/>\n*\/<\/p>\n<p>\/*<br \/>\nYou can start adding your own styles here. Use !important to overwrite styles if needed. *\/<\/p>\n<p>[\/code]<\/p>\n<h4>Note on Elmastudio Child themes:<\/h4>\n<p>At Elmastudio we also updated all your theme&#8217;s starter child theme folders to using the new method. In case you are already using a child theme you can update your child theme very easily as well.<\/p>\n<p>You only need to add the code showed above in the <em>functions.php<\/em> file of your child theme or create a new <em>functions.php<\/em> file for your child theme with the above explained code. You can also just download the example functions.php file we created to get you started.<\/p>\n<p>You also need to delete the following code snippet in your existing style.css:<\/p>\n<p>[code]<br \/>\n\/* This will import the stylesheet from the Theme Name parent theme *\/<br \/>\n@import url(&#8216;..\/yourthemename\/style.css&#8217;);<br \/>\n[\/code]<\/p>\n<h5>Your Feedback and Questions<\/h5>\n<p>Do you have further tips or questions regarding child themes? Please just write a comment to the post below, we are looking forward to hear from you!<\/p>\n<p>Further helpful links regarding WordPress child themes:<br \/>\n&#8211; <a href=\"https:\/\/codex.wordpress.org\/Child_Themes\">Child Theme information<\/a> on the WordPress.org website<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since recently it was considered best practice in WordPress to include the parent stylesheet (style.css) with the @import rule in your child theme&#8217;s style.css. However this technique got updated and now it&#8217;s best-practice to create a functions.php file for your child theme and use wp_enqueue_style() to include you parent theme stylesheet this way. I will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":149302,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1248,910,1247,1276],"tags":[1412,1401,1415],"class_list":["post-149194","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-popular","category-wordpress-en","category-wordpress-newbies","category-wordpress-tips","tag-child-theme-en","tag-featured-en","tag-parent-theme-en-2"],"_links":{"self":[{"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/posts\/149194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/comments?post=149194"}],"version-history":[{"count":0,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/posts\/149194\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/media\/149302"}],"wp:attachment":[{"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/media?parent=149194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/categories?post=149194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/tags?post=149194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}