子主题函数.php‘Parent-Style’:我应该将其命名为父主题名称吗?

时间:2020-04-23 作者:Robert Brax

创建子对象和设置初始函数时。php内容:

<?php
add_action( \'wp_enqueue_scripts\', \'my_theme_enqueue_styles\' );
function my_theme_enqueue_styles() {

$parent_style = \'parent-style\'; // <=====HERE

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 ),
    wp_get_theme()->get(\'Version\')
);
}
在本例中,我是否应该将“父样式”重命名为父样式的名称?还是将其保留为“父样式”?

1 个回复
最合适的回答,由SO网友:Tony Djukic 整理而成

您可以保持原样(参见Jacob Pettie的评论),也可以更改它,但这里的关键是添加路径以定位父主题的CSS。

<?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\' );
 
}
在您的示例中,您在(\'父样式\')之后将其切断,但您应该继续并包括父主题样式的路径。css。

get\\u template\\u directory\\u uri()用于父主题。

可在此处找到完整的逐步细分:https://developer.wordpress.org/themes/advanced-topics/child-themes/

相关推荐

Child-theme breaks site

所以,我有一个子主题,里面除了所需的CSS文件之外什么都没有。一旦我激活了这个儿童主题,我的整个网站就关闭了。最后我有两个问题:激活一个只有CSS的子主题怎么能破坏我的网站</我怎样才能回到我原来的主题</这些是网站给我的错误:Warning: require_once(/wp-content/themes/interio_child/admin/options-framework.php) [function.require-once]: 无法打开流:中没有此类文件或目录/wp-c