0

经过反复试验,我似乎创建了一个二十七的子主题,就像我之前创建的二十六一样,但是当仪表板显示我为我的主题选择的名称时,加载的样式表没有显示我的更改,因为我修改了子主题 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 作为其样式表?

谢谢,

- 更新 -

我的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从检查元素和跟踪样式表中看到。

4

1 回答 1

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' );
?>
于 2017-01-05T23:28:31.350 回答