【发布时间】:2019-05-27 23:51:52
【问题描述】:
我似乎无法让我的 WordPress 主题的 functions.php 文件加载我的样式表。
我在我的 WordPress 主题的主题目录中创建的文件及其各自的内容如下;
style.css
/*
Theme Name: Theme Study
Author: A
Version: 1.0.0
*/
body {
color: #4d5a6c !important;
}
header.php
<!DOCTYPE html>
<html lang="en">
<head>
<?php wp_head(); ?>
</head>
<body>
<h2>This is the header</h2>
index.php
<?php get_header();
while ( have_posts() ) {
the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content();
}
get_footer(); ?>
页脚.php
<h4>This is the footer</h4>
<?php wp_footer(); ?>
</body>
</html>
functions.php
<?php
function style_files() {
wp_enqueue_style( 'style_main', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'style_files' );
另一方面,我意识到当我直接引用我的 WordPress 主题的 header.phpfile as below, it works as expected, but my aim is to achieve that in thefunctions.php` 文件中的样式表时。
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>" />
<?php wp_head(); ?>
</head>
<body>
<h2>This is the header</h2>
为什么我的style.ccs 没有从functions.php 文件中加载?
【问题讨论】:
-
我已经尝试过上面的代码并且工作正常。我正在获取 style.css 文件
-
有没有办法查看或调试问题所在?
-
确保您的 style.css 位于主题根文件夹中,并要求您提供您的页面查看源,以便更好地了解。
-
我放源码
-
如果您尝试将 wp-config.php 中的
WP_DEBUG设置为true会怎样?所以应该是:define('WP_DEBUG', true);。您是否看到任何错误消息?
标签: css wordpress wordpress-theming