Child theme undefined variable error

admin2025-04-21  0

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 .

*/

// 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?

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/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?

Share Improve this question asked Aug 14, 2019 at 16:29 Jim DugganJim Duggan 893 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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'));
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745241625a292043.html

最新回复(0)