经过一些试验和错误后,似乎我创建了一个二十七岁的子主题,就像我之前的二十九岁一样,但是当仪表板显示我为我的主题选择的名称时,加载的样式表没有显示我的更改,因为我修改了子主题style.css,它正在加载原来的二十一个css;呈现的页面包括<link rel='stylesheet' id='twentyseventeen-style-css' href='https://cjshayward.com/wp-content/themes/twentyseventeen/style.css?ver=4.7' type='text/css' media='all' />
。
如何修改我的子主题,以便它使用自己的主题而不是父主题的样式表?
我的functions.php上写着:
<?php
update_option( 'siteurl', 'https://cjshayward.com' );
update_option( 'home', 'https://cjshayward.com' );
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
?>
到目前为止,我尝试的每件事都无法从自己的样式表/wp-content/themes/twentyseventeen-ux-tweaks-child/style.css
加载。编辑functions.php
无效。编辑header.php
没有用,**虽然我想知道是否有一些二次伤害,因为我没有说它使用我的孩子主题而不是二十七原版。用get_template_directory_uri()
替换'/wp-content/themes/twentyseventeen-ux-tweaks-child
无效。我可以通过Apache URL重写得到我想要的东西,但我真的很想知道正确的方式在Wordpress中做到这一点。
我需要正确注册子主题,以便它使用提供的子主题的style.css作为样式表?
谢谢,
- UPDATE -
我的functions.php现在写着:
<?php
update_option( 'siteurl', 'https://cjshayward.com' );
update_option( 'home', 'https://cjshayward.com' );
function my_theme_enqueue_styles() {
$parent_style = 'twentyseventeen';
wp_enqueue_style( $parent_style, get_template_directory_uri() .
'/style.css' );
wp_enqueue_style( 'twentyseventeen-ux-tweaks-child',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style )
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
我遇到了和以前一样的行为。我还没有看到https://cjshayward.com/wp-content/theme/twentyseventeen-ux-tweaks-child/style.css
来检查元素和跟踪样式表。
答案 0 :(得分:1)
根据wordpress.org,有必要同时使用父样式和子主题样式,因此应该是:
<?php
update_option( 'siteurl', 'https://cjshayward.com' );
update_option( 'home', 'https://cjshayward.com' );
function my_theme_enqueue_styles() {
$parent_style = 'twentyseventeen';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'twentyseventeen-ux-tweaks-child',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style )
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>