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?
is_single( 'pretty-little-liars' )
, NOTis_single() == 'pretty-little-liars'
. And enqueuing the stylesheets is enough. Don not print them manually into the header file.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.'pretty-little-liars'
is the slug of that post?