【发布时间】:2014-10-15 19:31:45
【问题描述】:
刚刚发现@import 不是导入样式表的最有效方法,尝试使用 enqueue。这有意义吗,尝试在不同的文件夹中导入几个父样式表:
<?php
/**
* Load the style sheet from the parent theme.
*
*/
function theme_name_parent_styles() {
// Enqueue the parent stylesheet
wp_enqueue_style( 'theme-name-parent-style', get_template_directory_uri() . '/style.css', array(), '0.1', 'all' );
wp_enqueue_style( 'theme-name-parent-style', get_template_directory_uri() . '/css/custom-admin-style.css', array(), '1', 'all' );
wp_enqueue_style( 'theme-name-parent-style', get_template_directory_uri() . '/css/flexslider.css', array(), '1', 'all' );
wp_enqueue_style( 'theme-name-parent-style', get_template_directory_uri() . '/css/thumbfx.css', array(), '1', 'all' );
wp_enqueue_style( 'theme-name-parent-style', get_template_directory_uri() . '/css/dynamic-css/options.css', array(), '1', 'all' );
// Enqueue the parent rtl stylesheet
if ( is_rtl() ) {
wp_enqueue_style( 'theme-name-parent-style-rtl', get_template_directory_uri() . '/rtl.css', array(), '0.1', 'all' );
}
}
add_action( 'wp_enqueue_scripts', 'theme_name_parent_styles' );
?>
【问题讨论】:
-
您能否提供有关您的问题的更多信息,或者这是一个代码审查请求?关于代码 - 您应该为不同的脚本使用不同的处理程序(入队函数的第一个参数),否则代码看起来没问题,这是在站点头部包含脚本的正确方法。
-
在我的functions.php子主题中添加了这个队列,因为这样做我的主要字体改变了试图让它回来。这是一个谜……考虑到所有样式表都已加载。
-
您是否使用 font-face 作为您的字体,如果是,在哪个 css 文件中?另外,您是否在某处使用 css 导入,例如:@import url('/css/fonts.css')?
-
我在 Wordpress codex 中阅读时删除了@import,最好在子主题中的 style.css 上入队而不是导入...所以我将 function.php 添加到带有入队的子项中。
-
您的问题可能出在 get_template_directory_uri() 函数中 - 它在子主题中使用时返回父主题的路径。检查get_template_directory_uri 和get_stylesheet_directory_uri。
标签: css wordpress stylesheet