简体   繁体   English

如何使用wordpress在没有.php文件扩展名的情况下获取get_page_template_slug()?

[英]How do I get get_page_template_slug() without the .php file extension with wordpress?

Basically what Im trying to do is 我基本上想做的是

wp_enqueue_style('pageStyle', get_template_directory_uri() . '/css/' . get_page_template_slug() . '.css', array(), null, 'all');

which works fine, but it outputs template.php.css how do I make it so that it's template.css instead? 哪个工作正常,但它输出template.php.css我该怎么做,以便它是template.css

try this - 尝试这个 -

str_replace(".php","",get_page_template_slug())

So your code will become - 因此,您的代码将变为-

wp_enqueue_style('pageStyle', get_template_directory_uri() . '/css/' . str_replace(".php","",get_page_template_slug()) . '.css', array(), null, 'all');

You can cut out the extension in your case, assuming this is what you want: 您可以根据自己的情况裁剪扩展名,假设这是您想要的:

pathinfo($file_path)['filename']

Will give you the file name of template.php without the extension (ie template ). 将给您没有扩展名的template.php文件名(即template )。

Complete line (assuming PHP 7+): 完整行(假设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