【发布时间】:2017-04-08 06:24:34
【问题描述】:
尝试导入自定义 CSS 样式表,但它没有显示在检查元素中并且无法正常工作。 style.css 位于根目录中名为 CSS 的文件夹中。有什么想法吗?
函数.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>
【问题讨论】:
-
在
view page source上找不到它?代码看起来不错 -
CSS 甚至无法正常工作。也不显示在检查元素中
-
你检查你的
function.php被调用了吗?尝试将一些日志放在那里并检查它是否有效,然后检查你的钩子是否被 WordPress 调用 -
我可以在functions.php 中编写显示的html 元素。不知道你所说的日志是什么意思? wordpress 新手,正在学习。
-
好的然后检查添加这一行
die('my hooks called');作为learningWordPress_resources的第一行然后重新加载页面。如果你看到我的钩子叫做 msg,那么你的钩子正在工作。不要在生产站点上尝试这个。