如何正确地加入子主题

时间:2018-12-20 02:52:14

标签: wordpress

我一直在尝试开发一个简单的儿童主题,以在我的网站上调整一些目前使用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文件中,但是我在Internet和wordpress Codex上发现的所有配置似乎都无法在我的网站上正常工作。当我激活通过代码创建的子主题时,该站点将还原为仅子主题样式表中的样式,而不是在子主题中未指定样式时退回到父主题样式表中。

2 个答案:

答案 0 :(得分:0)

  • 对于子主题,您首先需要使用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

谢谢,希望对您有所帮助。

答案 1 :(得分:0)

请使用One-Click Child Theme

安装并创建子主题

插件。这很容易使用

相关问题