最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Child theme undefined variable error

programmeradmin1浏览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'));

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论