SOLUTION
Big shoutout to the wonderful SallyM, who answered this very succinctly in the comments of this post.
If it helps anybody, here's the code that I used.
Note: Replace the //CONTENT// with your own site content
function include_template_specific_css() {
if (is_page_template('//TEMPLATEFILENAMEWITHDIRECTORY//.php'))
wp_enqueue_style('//CSSFILENAME//', get_template_directory_uri().'//CSSFILEURL//.css');
}
add_action('wp_enqueue_scripts', 'include_template_specific_css');
Good luck!
/SOLUTION
I'm attempting to call a specific stylesheet within the php of a new post template (one of four).
The stylesheet is 'Featured-Article.css'.
The template file is 'Featured-Article.php'.
Code I've attempted to place within the template includes:
<?php wp_enqueue_style('Featured-Article', get_stylesheet_directory_uri().'assets/css/Featured-Article.css',array('style')); ?>
and
<style> <?php include 'assets/css/Featured-Article.css'; ?> </style>
I'm wondering whether this is even possible at this point, short of meddling with functions.php to create a "if (is_page_template('Featured-Article.php')) etc" - something substantially beyond my ability!
Any ideas?
UPDATE 1:
It looks like the consensus is that such a callback must take place from within a theme's functions.php file. To this end, here's a draft code snippet that I'd hope might accomplish our aim, however sadly didn't work.
function //theme//_include_page_specific_css() {
if (is_page_template('Featured-Article.php'))
wp_enqueue_style('Featured-Article', get_template_directory_uri(). '/assets/css/Featured-Article.css'); }
add_action('wp_enqueue_style', 'Featured-Article');
}
Does anyone have any ideas?
UPDATE 2 - SOLVED
Big shoutout to the wonderful SallyM, who answered this very succinctly in the comments of this post.
If it helps anybody, here's the code that I used.
Note: Replace the //CONTENT// with your own site content
function include_template_specific_css() {
if (is_page_template('//TEMPLATEFILENAMEWITHDIRECTORY//.php'))
wp_enqueue_style('//CSSFILENAME//', get_template_directory_uri().'//CSSFILEURL//.css');
}
add_action('wp_enqueue_scripts', 'include_template_specific_css');
Good luck!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745314946a4622173.html
评论列表(0条)