尝试导入自定义 CSS 样式表,但它未显示在检查元素中且无法正常工作。 style.css 位于根目录中名为 CSS 的文件夹中。有什么想法吗?
Functions.php
<?php
function learningWordPress_resources() {
wp_enqueue_style('samirtheme-css', get_template_directory_uri().'/css/style.css', array(), '1.0.0', 'all');
// wp_enqueue_style('customstyle', get_template_directory_uri().'/css/style.css', array(), '1.0.0', 'all');
}
add_action('wp_enqueue_scripts', 'learningWordPress_resources');
?>
header.php
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width">
<title> <?php bloginfo('name') ?> </title>
<?php/* allows wordpress to add whatever it needs to */wp_head(); ?>
</head>
最佳答案
get_template_directory_uri()返回当前父主题文件夹的网络路径。如果您没有使用子主题,这也是您当前主题的文件夹。
但是,如果您不是创建供他人使用的主题的开发人员,您应该使用 get_stylesheet_directory_uri()它总是返回当前主题文件夹的网络路径(无论它是否是子主题)。
当然,您应该将自定义样式表放入
/wp-content/themes/{current_theme}/css/
如果将样式表放入根目录下的 /css
文件夹对您很重要,请使用 get_site_url() .
关于php - 使用 wp_enqueue_style() 导入样式表 - wordpress 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43290906/