[英]How do I get output from php file to display in a div on the wordpress page that called it?
[英]How do I get get_page_template_slug() without the .php file extension with wordpress?
我基本上想做的是
wp_enqueue_style('pageStyle', get_template_directory_uri() . '/css/' . get_page_template_slug() . '.css', array(), null, 'all');
哪個工作正常,但它輸出template.php.css
我該怎么做,以便它是template.css
?
嘗試這個 -
str_replace(".php","",get_page_template_slug())
因此,您的代碼將變為-
wp_enqueue_style('pageStyle', get_template_directory_uri() . '/css/' . str_replace(".php","",get_page_template_slug()) . '.css', array(), null, 'all');
您可以根據自己的情況裁剪擴展名,假設這是您想要的:
pathinfo($file_path)['filename']
將給您沒有擴展名的template.php
文件名(即template
)。
完整行(假設PHP 7+):
wp_enqueue_style('pageStyle', pathinfo(get_template_directory_uri() . '/css/' . get_page_template_slug())['filename'] . '.css', array(), null, 'all');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.