簡體   English   中英

如何使用wordpress在沒有.php文件擴展名的情況下獲取get_page_template_slug()?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM