• Resolved dorfird

    (@dorfird)


    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. 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. Reason: Formatting

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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

    (@dorfird)

    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.