enqueuing a specific stylesheet to a custom template

  • Author
  • #1480257


    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.



    That site is not a free hosted WordPress.com blog. We provide support only for free hosted WordPress.COM blogs being hosted right here on this multiuser blogging platform. You are posting to the wrong support forum.

    WordPress.com and WordPress.org have different log-ins and run different versions of themes with same names. If you don’t have a username account at WordPress.ORG click http://wordpress.org/support/ and register one on the top right hand corner of the page that opens, so you can post to the support forums there and receive advice from WordPress.ORG bloggers.

The topic ‘enqueuing a specific stylesheet to a custom template’ is closed to new replies.