自定义WordPress样式表未加载

时间:2019-08-17 06:55:25

标签: php wordpress wordpress-theming

我在这个主题上经历了许多其他话题,但是似乎对我来说都不起作用。

我正在尝试制作自己的WordPress主题,但始终出现此错误:

GET http:/ /placeholder-url.net/wp-content/themes/awesomethemecss/awesome.css?ver=1.0.0 net::ERR_ABORTED 404 (Not Found)

这是php:

function load_my_stylesheets() { 
wp_enqueue_style('customstyle', get_template_directory_uri() . 'css/awesome.css', array(), '1.0.0', 'all'); 
}
add_action('wp_enqueue_scripts', 'load_my_stylesheets');

这是我的测试CSS:

html, body {
    color: #333;
    background: #eee;
    font: sans-serif;
}

还有header.php:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Awesome Theme</title>
    <?php wp_head();?>
</head>
<body>

我缺少什么/做错了什么?

1 个答案:

答案 0 :(得分:0)

我认为您的wp_enqueue_script出错。

wp_enqueue_style('customstyle', get_template_directory_uri() . 'css/awesome.css', array(), '1.0.0', 'all')

将上述一项更改为

 wp_enqueue_style('customstyle', get_template_directory_uri() . '/css/awesome.css', array(), '1.0.0', 'all')

这是因为get_template_directory_uri()指向主题的路径。

在这里http:/ /placeholder-url.net/wp-content/themes/awesometheme,为了将此指向css文件夹中的样式表,您需要添加/css/awesome.css