php - 使用 wp_enqueue_style() 导入样式表 - wordpress 不工作

标签 php css wordpress

尝试导入自定义 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/

相关文章:

php - 从 MySQL 数据库中删除一条记录

php - 动态创建单元格时如何设置单元格的填充颜色? TCPDF

php - $_POST 和字符串中的变量 - 不确定为什么它不起作用

javascript - jQuery 没有给我 jQuery 对象

php - Woocommerce 子类别模板

javascript - 当 URL 中的哈希值发生变化时,使用 JS/jQuery 更改 CSS

html - 拆分 html 页面 : half code, 一半图像

php - fatal error : Call to a member function run() on null in {path to the test file}

html - 建一个HTML表格,TD宽度不均匀

javascript - 将功能组合到一个按钮