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.

Is there a way to have specific css on the homepage and use a different one for all the other pages?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Yes there is. You can add this to your themes header.

<?php
  if(is_home()){
    // we are on the home page
    echo '<link rel="stylesheet" src="your_stylesheet" />';
  }
?>

You can also use other conditional tags to find out if you are on nearly every type of WordPress page. Conditional Tags

Following on from the comments below, this would be better used like this

<?php
  if(is_home()){
    // we are on the home page
    echo '<link rel="stylesheet" src="your_home_stylesheet" />';
  }else {
    echo '<link rel="stylesheet" src="your_default_stylesheet" />';
  }
?>
share|improve this answer
    
this will work to but i prefer to use css tags body.home body.single etc. this keeps your css in one file –  xLRDxREVENGEx May 13 '11 at 1:02
    
That would work just as well. If your home page is completely different to the rest of the site though you probably don't want to load all the other styles in. –  supajb May 13 '11 at 1:06
    
true but i like i said above like to have very little amounts off css files. If i am not mistaken wont the above php code just add the homepage stylesheet to the wpheader and still show the main css –  xLRDxREVENGEx May 13 '11 at 1:08
1  
you're right it would. it might be best to used it with an else statement for all other pages. –  supajb May 13 '11 at 1:17
    
Thanks for the tips everyone! My other pages are very similar to the homepage but with a few changes. How can I implement the CSS tags xLRDxREVENGEx mentioned above? In other words, change the body.home vs body.single for the other pages in my theme. –  detonate May 13 '11 at 14:57

If you look at the source code on a WordPress page the body class changes for each page mine shows home so i would create my css with this

body.home #whatever div or body.home .whatever class

Look At The Body Tag

share|improve this answer
    
One little last not if you want a completely different looking homepage then create a home.php file inside the themes folder with all the things you want to be shown. As well you can register new widget locations and such. –  xLRDxREVENGEx May 13 '11 at 1:38

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.