如何在WordPress中将多个样式表排入我的子主题(Ocean Anwp)

时间:2020-05-29 作者:Phil

I would like to import several styles sheets in my child theme (oceanWP). I succeed to do it with "@import" method but not with enqueueing scripts and styles.

My child theme uses this "style.css" :

/*
 Theme Name:   oceanwp-child
 Theme URI:    https://monsite.com
 Description:  OceanWP WordPress theme example child theme.
 Author:       Phil
 Author URI:   https://voyageinitiartique.com
 Template:     oceanwp
 Version:      1.0.0
*/
/*@import url("./custom/navbar.css"); First, I try to import this with enqueueing method */
@import url("./custom/home.css");
@import url("./custom/voyages.css");
@import url("./custom/concept.css");
@import url("./custom/carnets.css");
@import url("./custom/contact.css");
@import url("./custom/articles.css");`

Child theme function.php :

function oceanwp_child_enqueue_parent_style() {
    // Dynamically get version number of the parent stylesheet (lets browsers re-cache your stylesheet when you update your theme)
    $theme   = wp_get_theme( \'OceanWP\' );
    $version = $theme->get( \'Version\' );
 // Load the stylesheet
       wp_enqueue_style( \'child-style\', get_stylesheet_directory_uri() . \'/style.css\', array (\'oceanwp-style\'), $version );
       wp_enqueue_style( \'child-navbar-style\', get_stylesheet_directory_uri() . \'./custom/navbar.css\', array( \'oceanwp-style\' ), $version );
}
add_action( \'wp_enqueue_scripts\', \'oceanwp_child_enqueue_parent_style\' );

Other syntax tried without success:

wp_enqueue_style( \'child-navbar-style\', get_stylesheet_directory_uri() . \'./custom/navbar.css\', array(), \'1.0\', \'all\' );

Is someone can help me ? Thx !

1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

你的想法是对的,但打错了字:. \'./custom/navbar.css\'.

删除额外的fullstop应该会更正URL,否则您将成功获取样式表,由于输入错误,代码只是将错误的URL排入队列

相关推荐

Child-theme breaks site

所以,我有一个子主题,里面除了所需的CSS文件之外什么都没有。一旦我激活了这个儿童主题,我的整个网站就关闭了。最后我有两个问题:激活一个只有CSS的子主题怎么能破坏我的网站</我怎样才能回到我原来的主题</这些是网站给我的错误:Warning: require_once(/wp-content/themes/interio_child/admin/options-framework.php) [function.require-once]: 无法打开流:中没有此类文件或目录/wp-c