admin管理员组文章数量:1384613
When creating child them and setting up the initial function.php content:
<?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')
);
}
In this exemple should I rename 'parent-style' as the name of the parent style? Or leave it as 'parent-style'?
When creating child them and setting up the initial function.php content:
<?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')
);
}
In this exemple should I rename 'parent-style' as the name of the parent style? Or leave it as 'parent-style'?
Share Improve this question asked Apr 23, 2020 at 16:13 Robert BraxRobert Brax 1353 bronze badges 1- 2 It’s not terribly important, but using a unique name, such as the theme name, reduces the chance of conflicts, although it’s unlikely a plugin will use the name ‘parent-style’. – Jacob Peattie Commented Apr 23, 2020 at 16:38
1 Answer
Reset to default 1You can leave it as is (see Jacob Pettie's comment) or you can change it, but the key here is to add the path to locate the parent theme’s 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' );
}
In your example you’re cutting it off after the ( ‘parent-style’ ), but you should continue and include the path to the parent theme’s style.css.
get_template_directory_uri() is for the parent theme.
The full step by step breakdown can be found here: https://developer.wordpress/themes/advanced-topics/child-themes/
本文标签: Child them functionphp 39parentstyle39 should I name this as parent theme name
版权声明:本文标题:Child them function.php 'parent-style': should I name this as parent theme name? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744537977a2611431.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论