如何在特定的WordPress块模板上加入CSS文件?
情况:我正在使用WordPress开发一个主题'new block主题paradigm 。我想为使用我的 templates/foo.html
模板的任何页面添加 foo.css
。
我尝试的是:我有此功能进行调试。
function foo_enqueue() {
echo '<pre>';
print_r(
get_page_template_slug(get_the_ID())
);
echo '</pre>';
}
add_action( 'wp_enqueue_scripts', 'foo_enqueue' );
使用 get_page_template_slug
函数的普通WordPress方法不适用于块主题模板。 get_page_template_slug
仅与传统的基于PHP的页面模板一起使用。
我设置了该调试功能,以查看它将返回的页面模板。它什么都没有。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在有条件的
模板/foo.html
的有条件地制定样式表中,请在基于块的主题中使用 get_post_meta(),使用键_wp_page_template
,eg:functions.php
ref:ref:ref:ref:https://developer.wordpress.org/reference/functions/get_page_template_slug/#more-信息
To conditionally enqueue a stylesheet only for
templates/foo.html
in a block-based theme, check the name of the currently applied template with get_post_meta(), using the key_wp_page_template
, eg:functions.php
Ref: https://developer.wordpress.org/reference/functions/get_page_template_slug/#more-information