1

I'm trying to make my own child theme from Twenty Fifteen. Everything looks and functions fine, but when I turn on debugging, I can see a PHP error:

Undefined variable: parent_style

on line 13 of functions.php of my child theme.

Here is the content of the functions.php file.

<?php /*

  This file is part of a child theme called spch.
  Functions in this file will be loaded before the parent theme's functions.
  For more information, please read https://codex.wordpress.org/Child_Themes.

*/

// this code loads the parent's stylesheet (leave it in place unless you know what you're doing)

function theme_enqueue_styles() {
    wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
    wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', array($parent_style));
}
add_action('wp_enqueue_scripts', 'theme_enqueue_styles');

/*  Add your own functions below this line.

What am I doing wrong?

3

In this line you use variable called $parent_style

wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', array($parent_style));

but you don’t define such variable anywhere in your code.

Most probably you want to use the slug of parent style instead:

wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style'));
  • Thank you for that explanation. I change the code as you suggested, and it works now. – Jim Duggan Aug 14 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.