0

Possible Duplicate:
is_singular won’t call my functions?

So I am trying to call different style sheets for each of my post types single page.

Here is the code I am using in my header file.

<?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" />';
}
if ( is_single() == 'revenge' )  {
echo '<link rel="stylesheet" href="http://www.tv-cafe.com/wp-content/themes/tvcafe/posttypecss/style-revenge.css" type="text/css" media="screen" />';
}
if ( is_single() == 'once-upon-a-time' )  {
echo '<link rel="stylesheet" href="http://www.tv-cafe.com/wp-content/themes/tvcafe/posttypecss/style-onceuponatime.css" type="text/css" media="screen" />';
}
}
?>

and I also learned that I had to add this code in my functions.php in order for it to work properly

add_action( 'wp_enqueue_scripts', 'wpse78368_enqueue_custom_stylesheet' );
function wpse78368_enqueue_custom_stylesheet() {
if ( is_single( 'pretty-little-liars' ) ) {
    wp_enqueue_style( 'style-pll', get_template_directory_uri() . '/posttypecss/style-pll.css' );
}
 if ( is_single( 'revenge' ) ) {
    wp_enqueue_style( 'style-revenge', get_template_directory_uri() . '/posttypecss/style-revenge.css' );
}
if ( is_single( 'once-upon-a-time' ) ) {
    wp_enqueue_style( 'style-onceuponatime', get_template_directory_uri() . '/posttypecss/style-onceuponatime.css' );
}
}

But the problem is that, the code is calling the last stylesheet of the code. It is calling the "Once Upon A Time" stylesheet for each custom post type singular page.

How can I fix this?

5
  • This is still the same error like in your last question: use is_single( 'pretty-little-liars' ), NOT is_single() == 'pretty-little-liars'. And enqueuing the stylesheets is enough. Don not print them manually into the header file.
    – fuxia
    Commented Jan 6, 2013 at 23:24
  • @toscho 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:33
  • And you are sure 'pretty-little-liars' is the slug of that post?
    – fuxia
    Commented Jan 6, 2013 at 23:38
  • @toscho "pretty-little-liars" is the custom post type i have added 2 more custom post type "revenge" and "once-upon-a-time" Each post type has a different stylesheet for the archive, but the single post under each post type doesn't. Now using what you and chip suggested seems not be really working, It's calling the style sheet from once upon a time, for every single post under every CPT, and yes thats the correct slug.
    – Mihad Aiko
    Commented Jan 6, 2013 at 23:47
  • Okay, I made an update to my previous answer to show the difference.
    – fuxia
    Commented Jan 6, 2013 at 23:51

0

Browse other questions tagged or ask your own question.