上个月,我创建了我的第一个网站。在此之前,我没有编码知识,所以我学到的每一件事对我来说都是新的。
上周我的问题是我的孩子主题。css文件(和php.file,但这是另一回事)并没有覆盖它们的父文件。css文件。我整个星期都在努力寻找解决方案,但到目前为止没有成功。
这是我在子函数中输入的代码。php文件
=========================================================================(5)-此代码允许最后读取子主题,但某些其他css(必须依赖其他内容?)导致一些错误/
<?php
function my_theme_enqueue_styles() {
$parent_style = \'adforest-original-modern\'; // This is \'adforest-style\' for the AdForest theme.
wp_enqueue_style( $parent_style, get_template_directory_uri().\'/css/modern.css\' );
wp_enqueue_style( \'child-style\',
get_stylesheet_directory_uri().\'/modern.css\',
array( $parent_style ),
wp_get_theme()->get(\'1.0.0\'));
}
add_action( \'wp_enqueue_scripts\', \'my_theme_enqueue_styles\' );
function wp_67472455() {
wp_dequeue_style( \'adforest-theme-modern\' );
wp_deregister_style( \'adforest-theme-modern\' );
}
add_action( \'wp_print_styles\', \'wp_67472455\', 100 );
?>
==========================================================
(6) -THIS FOLLOWING CODE WORKS, CAN ANYONE SEE POTENTIAL ISSUES WITH THIS CODE?
<?php
function my_theme_enqueue_styles() {
/* =================== modern.css ==========================*/
$parent_style = \'adforest-original-modern\'; // This is \'adforest-style\' for the AdForest theme.
wp_enqueue_style( $parent_style, get_template_directory_uri().\'/css/modern.css\' );
wp_enqueue_style( \'child-style\',
get_stylesheet_directory_uri().\'/modern.css\',
array( $parent_style ),
wp_get_theme()->get(\'1.0.0\'));
/* =================== default.css ==========================*/
wp_enqueue_style( \'defualt-original-color\', get_template_directory_uri().\'/css/colors/defualt.css\' );
wp_enqueue_style( \'child-defualt-color\',
get_stylesheet_directory_uri().\'/defualt.css\',
array( \'defualt-original-color\' ),
wp_get_theme()->get(\'1.0.0\'));
}
add_action( \'wp_enqueue_scripts\', \'my_theme_enqueue_styles\', 100 );
function wp_67472455() {
/* =================== modern.css ==========================*/
wp_dequeue_style( \'adforest-theme-modern\' );
wp_deregister_style( \'adforest-theme-modern\' );
/* =================== default.css ==========================*/
wp_dequeue_style( \'defualt-color\' );
wp_deregister_style( \'defualt-color\' );
}
add_action( \'wp_print_styles\', \'wp_67472455\', 1 );
?>
最合适的回答,由SO网友:harrison 整理而成
(非常感谢@D.Dan让我走上了正确的方向!)
这对我来说非常有效。即使在父主题更新我的孩子之后。css文件仍处于活动状态,并覆盖等效的父级。css文件。
此代码用于多个。css文件
<?php
function my_theme_enqueue_styles() {
/* =================== modern.css ==========================*/
$parent_style = \'adforest-original-modern\'; // This is \'adforest-style\' for the AdForest theme.
wp_enqueue_style( $parent_style, get_template_directory_uri().\'/css/modern.css\' );
wp_enqueue_style( \'child-style\',
get_stylesheet_directory_uri().\'/modern.css\',
array( $parent_style ),
wp_get_theme()->get(\'1.0.0\'));
/* =================== default.css ==========================*/
wp_enqueue_style( \'defualt-original-color\', get_template_directory_uri().\'/css/colors/defualt.css\' );
wp_enqueue_style( \'child-defualt-color\',
get_stylesheet_directory_uri().\'/defualt.css\',
array( \'defualt-original-color\' ),
wp_get_theme()->get(\'1.0.0\'));
/* =================== smart_wizard_theme_arrows.css ==========================*/
wp_enqueue_style( \'defualt_smart_wizard_theme_arrows\', get_template_directory_uri().\'/css/colors/smart_wizard_theme_arrows.css\' );
wp_enqueue_style( \'child-defualt_smart_wizard_theme_arrows\',
get_stylesheet_directory_uri().\'/smart_wizard_theme_arrows.css\',
array( \'defualt_smart_wizard_theme_arrows\' ),
wp_get_theme()->get(\'1.0.0\'));
/* =================== forest-menu.css ==========================*/
wp_enqueue_style( \'original-forest-menu\', get_template_directory_uri().\'/css/forest-menu.css\' );
wp_enqueue_style( \'child-forest-menu\',
get_stylesheet_directory_uri().\'/forest-menu.css\',
array( \'original-forest-menu\' ),
wp_get_theme()->get(\'1.0.0\'));
/* =================== responsive-media-modern.css ==========================*/
wp_enqueue_style( \'responsive-original-modern\', get_template_directory_uri().\'responsive-media-modern.css\' );
wp_enqueue_style( \'child-responsive-modern\',
get_stylesheet_directory_uri().\'/responsive-media-modern.css\',
array( \'responsive-original-modern\' ),
wp_get_theme()->get(\'1.0.0\'));
}
add_action( \'wp_enqueue_scripts\', \'my_theme_enqueue_styles\', 100 );
function wp_67472455() {
/* =================== modern.css ==========================*/
wp_dequeue_style( \'adforest-theme-modern\' );
wp_deregister_style( \'adforest-theme-modern\' );
/* =================== default.css ==========================*/
wp_dequeue_style( \'defualt-color\' );
wp_deregister_style( \'defualt-color\' );
/* =================== smart_wizard_theme_arrows.css ==========================*/
wp_dequeue_style( \'adforest-wizard-arrows\' );
wp_deregister_style( \'adforest-wizard-arrows\' );
/* =================== forest-menu.css ==========================*/
wp_dequeue_style( \'forest-menu\' );
wp_deregister_style( \'forest-menu\' );
/* =================== responsive-media-modern.css ==========================*/
wp_dequeue_style( \'responsive-media-modern\' );
wp_deregister_style( \'responsive-media-modern\' );
}
add_action( \'wp_print_styles\', \'wp_67472455\', 1 );
?>
SO网友:D. Dan
您应该将以下行添加到my\\u theme\\u enqueue\\u styles函数中:
wp_dequeue_style( \'adforest-theme-modern\' );
wp_deregister_style( \'adforest-theme-modern\' );
因为他们是以这个名字添加的。您已经将父css排队,这样它就可以在您的css之前加载。
Edit: 尝试:
function my_theme_enqueue_styles() {
$parent_style = \'adforest-theme-modern\'; // This is \'adforest-style\' for the AdForest theme.
wp_enqueue_style( $parent_style, get_template_directory_uri().\'/css/modern.css\' );
wp_enqueue_style( \'child-style\',
get_stylesheet_directory_uri().\'/modern.css\',
array( $parent_style ),
wp_get_theme()->get(\'1.0.0\'));
}
add_action( \'wp_enqueue_scripts\', \'my_theme_enqueue_styles\' );
function wp_67472455() {
wp_dequeue_style( \'adforest-theme-modern\' );
wp_deregister_style( \'adforest-theme-modern\' );
}
add_action( \'wp_print_styles\', \'wp_67472455\', 100 );