Title: Problem setting up child theme
Last modified: March 17, 2022

---

# Problem setting up child theme

 *  Resolved [dorfird](https://wordpress.org/support/users/dorfird/)
 * (@dorfird)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/problem-setting-up-child-theme/)
 * I am trying to create a child theme for the Advance Automobile free theme. When
   I choose “Live Preview” for my child theme, I get the error: “There has been 
   a critical error on this website. Please check your site admin email inbox for
   instructions.”
 * My style.css file starts out:
 *     ```
       /*
       Theme Name: Dave's Automotive
       Author: Ada Kerman
       Author URI: https://www.davesautoent.com/
       Description: Dave's Automotive, child theme of Advance Automobile for Dave's Automotive Enterprises of Marlborough, NH.
       Version: 0.1
       License: GPLv3.0 or later
       License URI: http://www.gnu.org/licenses/gps-3.0.html
       Text Domain: davesauto
       Template: advance-automobile
       */
       ```
   
 * after which it’s the same as the parent theme style.css file.
 * My functions.php file is:
 *     ```
       <?php
   
         // makes sure we don't expose any info if called directly
       if ( !function_exists( 'add-action' ) ) {
           echo 'Hi there! I'm just a plugin, not much I can do when called directly.';
           exit;
         }
   
       add_action( 'wp_enqueue_scripts', 'davesauto_enqueue_styles' );
       function davesauto_enqueue_styles() {
           $advance-automobile = 'advance-automobile';
           $theme = wp_get_theme();
   
           wp_enqueue_style( $advance-automobile, get_template_directory_uri() . '/style.css',
             array(), // if the parent theme code has a dependency, copy it to here
             $theme->parent()->get('Version')
           );
           wp_enqueue_style( 'davesauto', get_stylesheet_uri(),
               array( 'advance-automobile' ), 
               wp_get_theme()->get('Version') // this only works if you have Version in the style header
           };
       }
       ?>
       ```
   
    -  This topic was modified 4 years, 2 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not an Developing with WordPress
      topic
    -  This topic was modified 4 years, 2 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Formatting
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fproblem-setting-up-child-theme%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Vijay Hardaha](https://wordpress.org/support/users/vijayhardaha/)
 * (@vijayhardaha)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/problem-setting-up-child-theme/#post-15469860)
 * There are a few mistakes in your code.
 * 1. `$advance-automobile` dash is not allowed in a variable name.
    2. `echo 'Hi
   there! I'm just a plugin, not much I can do when called directly.';` you are 
   not escaping (‘) in `I'm` 3. `! function_exists( 'add-action' )` this will always
   return true because there is not function `add - action` it’s `add_action` with
   underscore. 4. You don’t need to check `add_action` you can do the same thing
   like this.
 *     ```
       // Exit if accessed directly.
       defined( 'ABSPATH' ) || exit;
       ```
   
 * So final code will be like this.
 *     ```
       // Exit if accessed directly.
       defined( 'ABSPATH' ) || exit;
   
       /**
        * Enqueue child theme script and styles.
        */
       function davesauto_enqueue_styles() {
       	$advance_automobile = 'advance-automobile';
       	$theme              = wp_get_theme();
   
       	wp_enqueue_style(
       		$advance_automobile,
       		get_template_directory_uri() . '/style.css',
       		array(),
       		$theme->parent()->get( 'Version' )
       	);
   
       	wp_enqueue_style(
       		'davesauto',
       		get_stylesheet_uri(),
       		array( $advance_automobile ),
       		$theme->get( 'Version' )
       	);
       }
       add_action( 'wp_enqueue_scripts', 'davesauto_enqueue_styles' );
       ```
   
 *  Thread Starter [dorfird](https://wordpress.org/support/users/dorfird/)
 * (@dorfird)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/problem-setting-up-child-theme/#post-15472731)
 * That fixed it, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Problem setting up child theme’ is closed to new replies.

## Tags

 * [child theme](https://wordpress.org/support/topic-tag/child-theme/)
 * [css](https://wordpress.org/support/topic-tag/css/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [dorfird](https://wordpress.org/support/users/dorfird/)
 * Last activity: [4 years, 2 months ago](https://wordpress.org/support/topic/problem-setting-up-child-theme/#post-15472731)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
