【发布时间】:2021-06-22 19:02:39
【问题描述】:
通常的入队方式是使用
wp_enqueue_styles('style', get_template_directory_uri() . '/bundle.css', array(), '', true);
从主题目录的根目录将bundle.css 加入队列。但是,我的主题目录在wp-content 之外,以支持将 php 文件与 scss 和 js 捆绑在一起,并且仍然保持 src 和 dist 目录分开。
在正常情况下get_template_directory_uri() 返回类似/wp-content/themes/... 和wp_enqueue_styles 生成<link href="http://localhost/wp-content/themes/...
但是当使用register_theme_dir 从wp_content 之外加载主题时,我得到<link href="http://localhostC:\projects\...,当然,WordPress 无法生成可以从网络服务器提供的链接,因为我的文件夹不在 htdocs 中,但是WordPress仍然将主机附加到本地文件系统路径没有任何意义。
有没有办法告诉 wp_enqueue_styles 使用我逐字传递的路径并且不附加主机?
当从另一个服务器排队样式时
wp_enqueue_styles('style', 'https://cdn.js...', array(), '', true);
它也没有附加我的主机,所以我尝试使用file:///,但这也没有用。
请注意,这仅适用于本地开发,因此可以在 htdocs 之外指定资源,当上传到 prod 时,所有内容都会打包为 zip 并上传到正常的 wp-content 目录。
【问题讨论】: