wordpress: the importance of a child theme

official documentation for child theme:

Child Themes

 

 

its critical to make a child theme, because if you don't do it every change you make will be overwritten every time you update your theme.

 

it is very easy to create:

  • you need to identify the name of your theme.
    • go to your themes folder (/var/www/html/[YOUR DOMAIN FOLDER]/wp-content/themes/[THEME_NAME]
    • on your desktop create a folder structure with the following files:
      • top folder: [THEME_NAME]-child
        • for example if your theme name is "sydney" you create the folder with the name "sydney-child"
      • files inside the folder:
        • functions.php
          • include the following text inside this file
            • <?php
              add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
              function enqueue_parent_styles() {
              wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
              }
              ?>

        • style.css
          • include the following text inside this file:
            • /*
              Theme Name: My Custom dt-the7 theme
              Template: dt-the7
              */

      • then zip this folder on your desktop (I use 7zip, but you can use the zip program of your choice)
      • then go to your WordPress admin dashboard -> Appearance -> Themes -> Add New -> upload the theme you just created and zipped -> activate the uploaded theme
      • from this moment on, you should be able to add the functions and edit your custom css to these 2 new files and they should be upgrade safe.

as always, make sure to make a backup of both your file system and your database prior to doing this, so in case something goes wrong you can restore.

Leave a Reply

Your email address will not be published. Required fields are marked *