按照说明为 Storefront 制作了一个子主题。
样式和脚本包含在/wp-content/themes/storefront/inc/class-storefront.php文件中。(第 204 行)
我需要添加我的样式,例如引导程序,我将 class-storefront.php 文件复制到我的主题 /wp-content/themes/mytheme/inc/class-storefront.php 并只保留函数
public function scripts() {
global $storefront_version;
/**
* Styles
*/
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array("storefront-style") );
}
头中的引导程序未连接,将其放入 /wp-content/themes/storefront/assets/css/bootstrap.min.css 和 /wp-content/themes/mytheme/assets/css/bootstrap.min.css 无论如何都没有连接。
我的 class-storefront.php 有什么问题?
发生了什么
并非所有主题文件都可以复制到子主题并预计会被拾取。这通常由开发人员在注释中特别指出,位于 php 文件的最顶部。
例如,打开
wp-content/plugins/woocommerce/templates/content-product.phpWooCommerce 插件中的文件并阅读上面的评论。此功能由插件代码提供。如果某些核心主题文件(如
header.php、footer.php等page.php)存在于子主题中,则它们会被 WordPress 核心拾取。该怎么办
该文件
class-storefront.php包含类定义。您可以创建自己的类来继承class Storefront和替换其中的函数。但为了你的目的,你甚至不需要那个。在子主题的functions.php中粘贴以下代码:
并将文件
bootstrap.min.css放在您的子主题文件夹中。