在WordPress中创建子主题时遇到问题

时间:2016-08-01 14:47:31

标签: css wordpress

您好我按照以下步骤操作: https://codex.wordpress.org/Child_Themes

并且仍然没有运气,主题激活很好,但父主题仍然保持完全活跃。

style.css中: enter image description here

的functions.php: enter image description here

文件位置& WP编辑: enter image description here enter image description here

非常感谢任何帮助,谢谢。同样,子主题似乎没有覆盖父主题dalton。

1 个答案:

答案 0 :(得分:1)

您不应该在您的子主题CSS中将父主题的样式表排入队列 - 这些样式表应该已经排队(如果您查看源代码,您可能会发现您只是获得了父主题的两个副本样式表到位)。

将您的子主题样式表排入队列:

add_action('wp_enqueue_scripts', 'my_the_enqueue_styles', 12); // Give this a lower priority so that it should be enqueued after the parent theme

function my_the_enqueue_styles() {
    wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css');
}

...然后,在你的孩子主题CSS中,添加一些明显的东西:

body {
    background-color: purple;
}

...您应该看到子主题样式表与父主题元素一起加载。

值得注意的是get_template_directory_uri()将始终引用父主题,而get_stylesheet_directory_uri()将始终引用当前活动的子主题。如果没有子/父主题并且您使用的是常规独立主题,则可以互换使用这些命令。

相关问题