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?
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
).
Complete line (assuming PHP 7+):
wp_enqueue_style('pageStyle', pathinfo(get_template_directory_uri() . '/css/' . get_page_template_slug())['filename'] . '.css', array(), null, 'all');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.