Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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().

share|improve this answer
    
Het @Toscho thanks, but doesn't add_action( 'wp_enqueue_scripts', 'wpse78368_enqueue_custom_stylesheet' ); go before function wpse78368_enqueue_custom_stylesheet() { –  Mihad Aiko Jan 5 '13 at 23:52
1  
@MihadAiko The order doesn’t matter. –  toscho Jan 5 '13 at 23:55
    
Ok, this works perfectly thank you :) –  Mihad Aiko Jan 5 '13 at 23:58
1  
Thank you too chip –  Mihad Aiko Jan 6 '13 at 0:35
    
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 Jan 6 '13 at 23:34
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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