admin管理员组文章数量:1323335
I want to know custom page template name (the one chosen in page attributes - template) in PHP, before page opens in order to enqueue additional scripts according to chosen template. I know how to get this information in javascript admin frontend part, however it would be more convenient if I could get it in PHP.
I want to know custom page template name (the one chosen in page attributes - template) in PHP, before page opens in order to enqueue additional scripts according to chosen template. I know how to get this information in javascript admin frontend part, however it would be more convenient if I could get it in PHP.
Share Improve this question asked Sep 4, 2020 at 9:23 LovorLovor 9969 silver badges16 bronze badges1 Answer
Reset to default 0You can use this code once set page template for specific post. If the template isn't set, you cant enqueue your script.
if ( $post->_wp_page_template === 'sky-template.php' ) {
wp_enqueue_script();
}
Remember to replace sky-template.php with your template file name.
Edit:
You can get some help from this question. _wp_page_template to dynamically use template
本文标签: customizationHow to get custom page template being edited in gutenberg editor
版权声明:本文标题:customization - How to get custom page template being edited in gutenberg editor 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742137401a2422430.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论