0

Hi i'm using this code to call for a different stylesheet for a single post type but the problem is, It won't call the stylesheet.

It's in header.php, i also tried placing it in single.php

<?php
if ( ! is_home() ) {

if ( is_single() == 'pretty-little-liars' )  {
    echo '<link rel="stylesheet" href="http://www.tv-cafe.com/wp-content/themes/tvcafe/posttypecss/style-pll.css" type="text/css" media="screen" />';
}
}
?>

can anyone tell me what the problem is?

0

1 Answer 1

6

is_single() returns TRUE or FALSE, not a string. Additionally, you can test for a specific post with is_single() function by putting the post slug into the function call:

if ( is_single( 'your-post-slug' ) )
{
    # do something
}

If you want to test for the proper post type use:

if ( is_singular() and 'your-post-type' === get_post_type() )

or just:

if ( is_singular( 'your-post-type' ) )

Edit

And for your specific question, you should wrap that script into a callback, hooked into wp_enqueue_scripts. In functions.php:

function wpse78368_enqueue_custom_stylesheet() {
    if ( is_singular( 'pretty-little-liars' ) ) {
        wp_enqueue_style( 
            'style-pll',
            get_template_directory_uri() . '/posttypecss/style-pll.css' 
        );
    }
}
add_action( 'wp_enqueue_scripts', 'wpse78368_enqueue_custom_stylesheet' );

Note: Use wp_enqueue_scripts because wp_enqueue_styles doesn't exist as a do_action().

5
  • Het @Toscho thanks, but doesn't add_action( 'wp_enqueue_scripts', 'wpse78368_enqueue_custom_stylesheet' ); go before function wpse78368_enqueue_custom_stylesheet() {
    – Mihad Aiko
    Commented Jan 5, 2013 at 23:52
  • 1
    @MihadAiko The order doesn’t matter.
    – fuxia
    Commented Jan 5, 2013 at 23:55
  • i didn't place the enueing in the header i placed it in the functions.php if i use is_single( 'pretty-little-liars' ) it won't work i have tried that. Are you saying that if i call it in functions.php i don't need to call it in the header, because it doesn't work by just calling it in the functions or just in the header.
    – Mihad Aiko
    Commented Jan 6, 2013 at 23:34
  • I'm trying to avoid creating a single-{custom post type}.php for each custom post type.
    – Mihad Aiko
    Commented Jan 6, 2013 at 23:52
  • @toshco Thank you that works great lol :) Thank you for so much of your help. I'm learning a bit more :)
    – Mihad Aiko
    Commented Jan 6, 2013 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.