【问题标题】:How properly enqueue a child theme如何正确地将子主题排入队列
【发布时间】:2018-12-20 13:09:38
【问题描述】:

我一直在尝试开发一个简单的子主题来调整我目前使用 vantage 主题的网站上的一些内容。到目前为止,我几乎没有成功。

我创建的两个文件(style.css 和 function.php)只有几行代码,但我仍然无法查明问题。

<?php
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', 
PHP_INT_MAX);
function enqueue_child_theme_styles() {
wp_enqueue_style( 'parent-style', 
get_template_directory_uri().'/style.css' );
}
?>



/*
Theme Name: vantage-child
Template: Vantage
*/
body {
color:aqua; 
}

我怀疑问题出在 PHP 文件中的排队,但我在互联网上找到的所有配置和 wordpress 代码似乎都不适用于我的网站。当我激活由我的代码创建的子主题时,该站点将恢复为仅我的子主题样式表中的样式,而不是在子主题中未指定样式时退回到父主题的样式表。

【问题讨论】:

    标签: wordpress


    【解决方案1】:
    • 对于子主题,您首先需要使用 themename-child 创建文件夹。
    • 然后你必须创建 style.css 文件。
    • 在你的 style.css 中加入下面几行

      /* Theme Name: Twenty Fourteen Child Theme URI: http://yourwebsite.com/twentyfourteen-child/ Description: My first child theme, based on Twenty Fourteen Author: Joshi Niket Template: twentyfourteen Text Domain: twenty-fourteen-child */

    • 然后在子主题文件夹中创建functions.php并放入以下代码。

      <?php add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); } ?>

    • 请检查以下链接以正确步骤制作子主题,我在这里添加了一些指导您。ReferenceLink

    谢谢,希望对你有帮助。

    【讨论】:

    • 这似乎是一个可靠的答案,但它仍然不能完全解决我的问题。我只是将上面的 PHP 复制粘贴到我的 functions.php 文件中,还是应该根据我正在使用的主题对其进行自定义?例如,如果父主题是“twentyfifteen”,我是否将“function my_theme_enqueue_styles()”更改为“function twofifteen_enqueue_styles()”? “父式”应该是“二十五式”吗?
    • 是的,伙计,您可以根据自己的主题使用它,因为它已经过全面测试并且适合我,但请确保 style.css 文件名永远不会根据主题名称或其他任何内容发生变化
    • 欢迎 @JakeDoe 我很高兴听到这个
    【解决方案2】:

    请使用One-Click Child Theme安装和创建子主题

    插件。这很容易使用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多