在查看与排队样式相关的父主题源代码后,您发布的原始代码看起来很接近。您只需要使用父主题的句柄,adios-main-style
. 添加wpse244754_child_theme_enqueue_styles()
到您孩子的主题functions.php
文件:
add_action( \'wp_enqueue_scripts\', \'wpse244754_child_theme_enqueue_styles\' );
function wpse244754_child_theme_enqueue_styles() {
// Enqueue the parent theme\'s stylesheet
wp_enqueue_style( \'adios-main-style\', get_template_directory_uri() . \'/css/style.css\');
// Enqueue the child theme\'s stylesheet, specifying the parent theme\'s
// styles as a dependency.
wp_enqueue_style( \'child-style\',
get_stylesheet_directory_uri() . \'/style.css\',
array( \'adios-main-style\' ) // dependency
);
}
儿童主题
functions.php
(及其包含项)将在父主题的
functions.php
.
正在查看wpse244754_child_theme_enqueue_styles()
, 父主题的style.css
将首先加载。我们已经指定adios-main-style
作为子主题样式的依赖项,确保子主题的样式将在父主题的样式之后加载。
当父主题尝试排队时adios-main-style
, 由于这种方式,它不会再次加载wp_enqueue_style()
作品
Another approach父主题的adios_enqueue_scripts()
功能是可插拔的。因此,另一种选择是将整个功能复制到您的子主题,并根据需要对其进行自定义,例如:
function adios_enqueue_scripts() {
if( ( is_admin() ) ) { return; }
if ( is_singular() ) { wp_enqueue_script( \'comment-reply\' ); }
// enqueue script
wp_enqueue_script( \'adios-scrollify\', get_template_directory_uri() .\'/js/jquery.scrollify.min.js\',array(\'jquery\'), ADIOS_THEME_VERSION,true);
wp_enqueue_script( \'adios-wow\', get_template_directory_uri() .\'/js/wow.min.js\',array(\'jquery\'), ADIOS_THEME_VERSION,true);
wp_enqueue_script( \'adios-count\', get_template_directory_uri() .\'/js/jquery.countTo.js\',array(\'jquery\'), ADIOS_THEME_VERSION,true);
wp_enqueue_script( \'adios-isotope\', get_template_directory_uri() .\'/js/isotope.pkg.min.js\',array(\'jquery\'), ADIOS_THEME_VERSION,true);
wp_enqueue_script( \'adios-img-loaded\', get_template_directory_uri() .\'/js/jquery.imageloaded.js\',array(\'jquery\'), ADIOS_THEME_VERSION,true);
wp_enqueue_script( \'adios-all\', get_template_directory_uri() .\'/js/all.js\',array(\'jquery\'), ADIOS_THEME_VERSION,true);
// register script
wp_register_script( \'adios-gmapsensor\', \' http://maps.google.com/maps/api/js?sensor =false\',array(\'jquery\'), ADIOS_THEME_VERSION,true);
wp_register_script( \'adios-swiper\', get_template_directory_uri() .\'/js/swiper.min.js\',array(\'jquery\'), ADIOS_THEME_VERSION,true);
wp_register_script( \'adios-cd-google-map\', get_template_directory_uri() .\'/js/map.js\',array(\'adios-gmapsensor\'), ADIOS_THEME_VERSION,true);
wp_register_script( \'adios-youtube\', get_template_directory_uri() .\'/js/jquery.youtubebackground.js\',array(\'jquery\'), ADIOS_THEME_VERSION,true);
wp_localize_script(\'adios-cd-google-map\', \'get\',
array(
\'ajaxurl\' => esc_url(admin_url( \'admin-ajax.php\' )),
\'siteurl\' => get_template_directory_uri()
)
);
wp_enqueue_style( \'adios-fonts\', adios_fonts_url(), null, ADIOS_THEME_VERSION );
wp_enqueue_style( \'adios-bootstrap\', get_template_directory_uri(). \'/css/bootstrap.min.css\',null, ADIOS_THEME_VERSION);
wp_enqueue_style( \'adios-main-style\', get_template_directory_uri(). \'/css/style.css\',null, ADIOS_THEME_VERSION);
// *** Child theme style added here ***
wp_enqueue_style( \'adios-child-style\', get_stylesheet_directory_uri(). \'/style.css\', array( \'adios-main-style\' ), ADIOS_THEME_VERSION);
wp_enqueue_style( \'adios-fonttello\', get_template_directory_uri(). \'/css/fontello.css\',null, ADIOS_THEME_VERSION);
wp_enqueue_style( \'adios-animate\', get_template_directory_uri(). \'/css/animate.css\',null, ADIOS_THEME_VERSION);
// register
wp_register_style(\'adios-swiper\', get_template_directory_uri(). \'/css/idangerous.swiper.css\',null, ADIOS_THEME_VERSION);
// Custom CSS
$css_code = adios_get_opt(\'css_editor\');
$style = \'\';
$style .= ( !empty($css_code)) ? $css_code:\'\';
wp_add_inline_style(\'main-style\', $style);
}
add_action( \'wp_enqueue_scripts\', \'adios_enqueue_scripts\' );
如果您只想为子主题添加样式表,那么这种方法就太过分了,但是如果您正在进行广泛的定制,那么这种方法就很方便了。