enqueue_stylesheet 但它不适用于 wordpress 主题开发
enqueue_stylesheet but it is not working on wordpress theme development
我最近下载了一个主题并尝试将其转换为 wordpress 主题。
现在我陷入了错误,我正在尝试将我的样式 sheet 脚本排入主题,但它不起作用。
这是我的 header,我在其中使用 wp_head() 标记来挂钩我的入队函数
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Document Title
============================================= -->
<title>Index Template</title>
<!-- <link rel="stylesheet" href="" type="text/css" /> -->
<?php wp_head(); ?>
</head>
这是我的加载样式 sheet 函数代码和 add_action 函数用于将函数挂接到 header
function ft_loadScripts()
{
wp_register_style( 'ft_style', get_stylesheet_uri() );
wp_enqueue_style( 'ft_style' );
}
add_action( 'wp_enqueue_scripts','ft_loadScripts' );
这是我的主要风格 sheet 为主题创建的它位于主题文件夹中
在这种风格中 sheet 我只使用 body 背景颜色来测试代码。
/*
Theme Name: Firstweb
Theme URI: https://wordpress.org/themes/Firstweb/
Author:John don
Author URI: https://wordpress.org/
Description: Our default theme for 2020 is designed to take full advantage of the flexibility of the block editor. Organizations and businesses have the ability to create dynamic landing pages with endless layouts using the group and column blocks. The centered content column and fine-tuned typography also makes it perfect for traditional blogs. Complete editor styles give you a good idea of what your content will look like, even before you publish. You can give your site a personal touch by changing the background colors and the accent color in the Customizer. The colors of all elements on your site are automatically calculated based on the colors you pick, ensuring a high, accessible color contrast for your visitors.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: Firstweb
*/
body{
background-color: black;
}
这是我的文件夹结构
在资产文件夹中
我的主题是这样的
但我不知道为什么它不起作用。我还检查了开发人员工具,控制台中没有样式 sheet 的错误,但样式 sheet 仍然根本不起作用
somebody 请帮我解决这个问题
提前谢谢你
据我所知,代码片段应该都可以正常工作。但是,看起来您的 functions.php
被称为 function.php
(没有“s”),导致 Wordpress 忽略该文件。希望重命名文件可以解决您的问题!
我最近下载了一个主题并尝试将其转换为 wordpress 主题。
现在我陷入了错误,我正在尝试将我的样式 sheet 脚本排入主题,但它不起作用。
这是我的 header,我在其中使用 wp_head() 标记来挂钩我的入队函数
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Document Title
============================================= -->
<title>Index Template</title>
<!-- <link rel="stylesheet" href="" type="text/css" /> -->
<?php wp_head(); ?>
</head>
这是我的加载样式 sheet 函数代码和 add_action 函数用于将函数挂接到 header
function ft_loadScripts()
{
wp_register_style( 'ft_style', get_stylesheet_uri() );
wp_enqueue_style( 'ft_style' );
}
add_action( 'wp_enqueue_scripts','ft_loadScripts' );
这是我的主要风格 sheet 为主题创建的它位于主题文件夹中
在这种风格中 sheet 我只使用 body 背景颜色来测试代码。
/*
Theme Name: Firstweb
Theme URI: https://wordpress.org/themes/Firstweb/
Author:John don
Author URI: https://wordpress.org/
Description: Our default theme for 2020 is designed to take full advantage of the flexibility of the block editor. Organizations and businesses have the ability to create dynamic landing pages with endless layouts using the group and column blocks. The centered content column and fine-tuned typography also makes it perfect for traditional blogs. Complete editor styles give you a good idea of what your content will look like, even before you publish. You can give your site a personal touch by changing the background colors and the accent color in the Customizer. The colors of all elements on your site are automatically calculated based on the colors you pick, ensuring a high, accessible color contrast for your visitors.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: Firstweb
*/
body{
background-color: black;
}
这是我的文件夹结构
在资产文件夹中
我的主题是这样的
但我不知道为什么它不起作用。我还检查了开发人员工具,控制台中没有样式 sheet 的错误,但样式 sheet 仍然根本不起作用
somebody 请帮我解决这个问题 提前谢谢你
据我所知,代码片段应该都可以正常工作。但是,看起来您的 functions.php
被称为 function.php
(没有“s”),导致 Wordpress 忽略该文件。希望重命名文件可以解决您的问题!