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 creating my first WordPress theme and I'm new to PHP. I've done some looking around but I can't seem to find my specific answer.

In my header.php I want to include some conditional logic to set CSS for all pages except the home page. This is my current code but there must be a better way.

Couple of other things I'm wondering about... Do I need to make sure the admin doesn't pick up these styles and is my method considered a 'best practice' or is there a better way to go about this?

<!--The Global Styles -->
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" media="screen" />
<!-- Styles specific to the home page -->
<?php if(is_home() || is_front_page()) :?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/ot_nav_widget.css" media="screen" />    
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/birdcage.css" media="screen" />
<?php endif;?>
 <!-- Set styles for any pages other than the home page -->
<?php if(!is_home() || !is_front_page()) :?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/ot_internal_nav_widget.css" media="screen" />
<?php endif;?>
share|improve this question
I suspect the down-vote is because this question is answered more completely elsewhere? In the spirit of helpfulness would the down-voter mind including a link to the duplicate answer for other folks that might come across this? – Ofeargall Feb 13 '13 at 15:35
up vote 2 down vote accepted

Instead of

<?php if(!is_home() || !is_front_page()) :?>

you could use

<?php else: ?>

This style will not affect the wp-admin part, only the front end of your web since this is used in header.php.

A safe way is to use wp_register_style() and wp_enqueue_style() as described here in the Codex:

http://codex.wordpress.org/Function_Reference/wp_enqueue_style http://codex.wordpress.org/Function_Reference/wp_register_style

In your case it could be:

function wpse85659_theme_styles()  
  // Register the styles
  wp_register_style( 'global-style', get_template_directory_uri() . '/style.css', array(), '20130213', 'screen' );
  wp_register_style( 'home-widget-style', get_template_directory_uri() . '/css/ot_nav_widget.css', array('global-style'), '20130213', 'screen' );
  wp_register_style( 'home-birdcage-style', get_template_directory_uri() . '/css/birdcage.css', array('global-style','home-widget-style'), '20130213', 'screen');
  wp_register_style( 'internal-widget-style', get_template_directory_uri() . '/css/ot_internal_nav_widget.css', array('global-style'), '20130213', 'screen' );

  // Enqueing:
  wp_enqueue_style( 'global-style' );
  if(is_home() || is_front_page()) :
    wp_enqueue_style( 'home-widget-style' );
    wp_enqueue_style( 'home-birdcage-style' );
    wp_enqueue_style( 'internal-widget-style' );

add_action('wp_enqueue_scripts', 'wpse85659_theme_styles');

You can place this code example into your functions.php file. Just remember to use the wp_head() in your header.php for this method.

share|improve this answer
This is an extraordinarily helpful answer. Thank you for the code samples as I am a beginner in this arena. I've been a ColdFusion programmer for a while and this is all new territory for me. – Ofeargall Feb 13 '13 at 15:31

Your Answer


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.