enqueuing a specific stylesheet to a custom template
-
Hi, as the title states I’m attempting to enqueue a seperate stylesheet to a specific custom template that I have made within my theme, as it will require a different layout than the rest of the pages on my site.
This is the function that I have currently in my functions.php file:
function shape_scripts() {
if ( is_page_template( ‘no-sidebar.php’ ) ) {
wp_register_style(‘style-no-sidebar’, get_template_directory_uri() . ‘/style-no-sidebar.css’);
wp_enqueue_style( ‘style-no-sidebar’, get_stylesheet_uri() );}else {
wp_enqueue_style( ‘style’, get_stylesheet_uri() );
if ( is_singular() && comments_open() && get_option( ‘thread_comments’ ) ) {
wp_enqueue_script( ‘comment-reply’ );
}wp_enqueue_script( ‘navigation’, get_template_directory_uri() . ‘/js/navigation.js’, array(), ‘20120206’, true );
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( ‘keyboard-image-navigation’, get_template_directory_uri() . ‘/js/keyboard-image-navigation.js’, array( ‘jquery’ ), ‘20120202’ );
}
}
add_action( ‘wp_enqueue_scripts’, ‘shape_scripts’ );So, through lots of reading of the codex and trying different ways of it this is what I have and it doesnt work, so I have obviuosly done something wrong somwhere. Just to be clear Im trying to say if the current page is the template no-sidebar.php then use the stylesheet style-no-sidebar.css; and if not then use style.css.
Any help would be greatly appreciated. Thanks.
-
duplicate > already answered here https://en.forums.wordpress.com/topic/enqueuing-a-specific-stylesheet-to-a-custom-template?replies=2
- The topic ‘enqueuing a specific stylesheet to a custom template’ is closed to new replies.