Different CSS Styles For Different Pages And Categories In WordPress

We all know the fact that every theme comes with its own CSS style sheet and that CSS gives a design to all the pages, posts, comments etc of the blog. If we want to customize it we can easily do it by “Theme Editor” in wordpress. But what if we want a totally different CSS for a particular page or category. Well this can be done with a little bit of tweaking with code in Header.php file. And here is how to do it .

Before we begin I assume that you have both CSS files i.e Theme Default CSS (lets call it style.css) and your desired CSS for a particular page or category (lets call it style2.css)

CSS Styles

Different CSS For a Particular Page

Suppose your page title is “My Page” and you want to have a different CSS for this page. Login to your wordpress dashboard and go to Theme Editor and click on “header.php”, then locate where you theme’s default CSS is declared. Replace it with the following code :-

<?php if ( is_page(‘My Page’) ) { ?>

<link rel=”stylesheet” href=”URL of style2.css” type=”text/css” media=”screen” />

<?php } else { ?>

<link rel=”stylesheet” href=”URL of style.css” type=”text/css” media=”screen” />

<?php } ?>

In the ‘If’ statement you can use Page-slug and Page-ID also.

If in case you want to use different CSS for multiple pages then use following code:-

<?php if( is_page(‘My Page’) ) { ?>

<link rel=”stylesheet” href=”URL of style2.css” type=”text/css” media=”screen” />

<?php } elseif ( is_page(‘My Page1′) ) { ?>

<link rel=”stylesheet” href=”URL of style3.css” type=”text/css” media=”screen” />

<?php } elseif (is_page(‘My Page2′) ) { ?>

<link rel=”stylesheet” href=”URL of style4.css” type=”text/css” media=”screen” />

<?php } else { ?>

<link rel=”stylesheet” href=”URL of style.css” type=”text/css” media=”screen,projection” />

<?php  }  ?>

Different CSS For Categories

For having different CSS for the categories use the following code :-

<?php if( is_category( 1 ) ) { ?>
<link rel=”stylesheet” href=”URL of style1.css” type=”text/css” media=”screen” />
<?php } elseif ( is_category (2) ) { ?>
<link rel=”stylesheet” href=”URL of style2.css” type=”text/css” media=”screen” />
<?php } elseif ( is_category (3) ) { ?>
<link rel=”stylesheet” href=”URL of style2.css” type=”text/css” media=”screen” />
<?php } else {  ?>
<link rel=”stylesheet” href=”URL of style.css” type=”text/css” media=”screen,projection” />
<?php  }  ?>

Here 1,2&3 represents Category ID’s and style1.css, style2.css & style3.css represents their different CSS repectively.

Do share your views with us :)

Comments

Similar articles

Does The Cloud Really Make A Difference For Your Business?

The era of the physical office space may be dwindling for small businesses. Most small companies are now choosing to go to virtual offices. Many functions of physical offices are now being done more comfortably by virtual offices from the comfort of the employees’ own homes. Business is moving into

Dropbox Hacking Confirmed, Assures it is Safe Now

Dropbox is a file hosting service operated by Dropbox, Inc. that offers cloud storage, file synchronization, and client software. In brief, Dropbox allows users to create a special folder on each of their computers,

Facebook Scores Higher Emotional engagement and Memory Retention

A study commissioned by Facebook examined why Facebook elicits such an emotional response and how consumers’ brains responded to the site as well as to Yahoo’s and The New York Times ‘s homepages. The study, found that of the three, Facebook scored highest on attention.

Few Mistakes Internet Marketers Should Avoid

The vast majority of internet marketers will never make any money and they will quit. So they just quit and say it’s all a scam, and that’s after they make the kinds of mistakes that practically ensure their failure. Yet, it’s so easy to verify that tons of people are making money online and in busi

Google Launches Youtube Apps for Google+ Hangouts

Everyone wants to be a charm of the party for that we many a times starts showing everyone latest cool YouTube video, snaps etc on laptops, iphones and succeed grabing attention at that place.

Google Should Pay $750 a book, say authors in copyright case

Authors suing Google over the digitization of their books have asked a New York court to order the Internet company to pay $750 for each book it copied, distributed or displayed.

*Disclaimer: Any or all product name(s) and company logo(s) used on the website are registered and trademarked by their respective owners.