WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to import independent stylesheets for the blog page, gallery page and the contact page but I'm having some trouble getting this to work.

<link rel="stylesheet" type="text/css" href="<?php bloginfo('http://www.dannysgallery.com/tracy/wp-content/themes/infocus/styles/deep_blue.css'); ?>" media="screen" />
<?php if(is_page_template('contact-4')) :?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('http://www.dannysgallery.com/tracy/contact-4'); ?>/contactstyles.css" media="screen" />
<?php endif;?>

This is the header:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>

<link rel="stylesheet" href="<?php echo bloginfo('template_url'); ?>/lib/scripts/prettyPhoto/css/prettyPhoto.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

<?php require(WEBTREATS_INCLUDES . "/var.php"); ?>

<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_directory'); ?>/styles/<?php echo $color_scheme; ?>" />

<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
<?php wp_head(); ?> 

<meta name="disable_cufon" content="<?php echo $cufon_disable; ?>" />
<meta name="slider_speed" content="<?php echo $slider_speed; ?>" />
<meta name="slider_disable" content="<?php echo $slider_disable; ?>" />

$css_style_path = str_replace('.css', '', $color_scheme);
if($css_style_path == 'black') {
    $css_style_path = '/images';
    $css_style_path = '/styles/' .$css_style_path;
$template_dir = get_template_directory_uri();
if(is_home()) { ?>

<script type="text/javascript">
/* <![CDATA[ */
jQuery.preloadImages("<?php echo $template_dir.$css_style_path; ?>/home_feature.jpg","<?php echo $template_dir.$css_style_path; ?>/stage.jpg","<?php echo $template_dir.$css_style_path; ?>/header.jpg","<?php echo $template_dir; ?>/images/slider_inactive.png","<?php echo $template_dir; ?>/images/buttons.gif","<?php echo $template_dir.$css_style_path; ?>/buttons.gif","<?php echo $template_dir; ?>/images/slider_active.png","<?php echo $template_dir.$css_style_path; ?>/drop.png","<?php echo $template_dir.$css_style_path; ?>/dropR.png","<?php echo $template_dir.$css_style_path; ?>/drop_sub.png");
/* ]]> */
<?php } ?>

<!--[if IE 6]>
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/styles/ie6/ie6.css" type="text/css" media="screen" />
<script src="<?php echo WEBTREATS_JS; ?>/DD_belatedPNG_0.0.8a-min.js"></script>
    DD_belatedPNG.fix('#default_logo, .slider_frame');


Can anyone explain to me how to get this to work?

Thank you Dan

share|improve this question
You're not suppose to pass a complete address into bloginfo() (first code sample posted), bloginfo() is a function for returning specific options based on a key, some of the possible values are listed here. – t31os Mar 4 '11 at 16:36
so it should be this, <?php bloginfo('deep_blue'); ?> and this <?php bloginfo('contact-4'); ?> – user3707 Mar 4 '11 at 16:42
Neither of those will do anything. bloginfo() only accepts certain strings ... which are all listed on the Codex page t31os linked to above. – EAMann Mar 4 '11 at 17:05

There's a part in your header template that's already doing conditional loading:

<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>

This code loads the JavaScript for comments into the queue; WordPress then loads all of the scripts when it fires the wp_head() trigger.

My recommendation would be to use your functions.php file to register the scripts, then use wp_enqueue_style() to load them.

In functions.php

You'll first need to register all of your scripts. Use code similar to this:

function my_load_styles() {
    $template_uri = get_template_directory_uri();

    wp_register_style( 'my-blog-page', $template_uri . '/styles/blog-page.css', '', '1.0' );
    wp_register_style( 'my-gallery-page', $template_uri . '/styles/gallery-page.css', '', '1.0' );
add_action( 'init', 'my_load_styles' );

This will register all of your various stylesheets with WordPress. Then you can pick and choose which ones will be loaded.

In header.php

Just below the <?php if ( is_singular() ) ... line, add the following:

<?php if ( is_page_template( 'blog-page.php' ) ) wp_enqueue_script( 'my-blog-page '); ?>
<?php if ( is_page_template( 'gallery-page.php' ) ) wp_enqueue_script( 'my-gallery-page '); ?>

If you're using the page template identified in the conditional (remember to use the full page template file name), then WordPress will add that template's stylesheet to the queue and echo it to the browser. No need to do it yourself.

share|improve this answer
thank you for the clear explaination. I will give this a try and let you know how it works out. Once again, thank you. – user3707 Mar 4 '11 at 18:35

First, your usage of bloginfo() is a little strange. It only accepts list of specific strings, no sense in passing URLs to it.

And while you can just echo stylesheets in template it is usually preferable to use wp_enqueue_style() to queue them (with support for dependencies and such) and let WP do the echoing.

share|improve this answer
Thanks Rarst, that was explained above :) – user3707 Mar 4 '11 at 18:37
@Dan above and below don't apply much around here. :) Answers shift their order depending on how long ago they were made, their votes and sort method (can be chosen right above answers block). – Rarst Mar 4 '11 at 18:56

Your Answer


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