This feels like a fairly simple question, though I fear, may be a complicated answer. Is there an way (via plugin or code) to make a theme change some basic CSS elements based on a taxonomy term.

So if you have camera brands, and you site is all about cameras. Can you have pages about Kodak use a CSS file where colors are blue, and if Cannon it uses a CSS file that is red, etc. Basically you sub-theme your theme based on a taxonomy term?

2 Answers 2


Yes, you can. In many ways.

One way is to have custom templates based on tag or category slug. So, you just tag your posts appropriately and then WordPress will automatically select appropriate template.

If the template difference are miniscule, you can use php includes or wordpress includes to keep common content in other files.

Or you could do a custom include based on the value of the tag from the main theme file and provide CSS reference that way.

Or have inline CSS again controlled by php code inside the template.

  • My changes will be cosmetic. Where was blue now red. Image A now Image B. Very cosmetic. What I have are Pages with tags, and then some custom post types that need to have basically a CSS include in them depending on which color scheme they get. Alexandre, still the correct idea? Jan 7, 2011 at 23:56
  • Why don't you just have a CSS file with name that incorporates the tag name? Then just get the tag name in the single.php template and use it to form the CSS file reference. It is probably easier to try it than to think it through. You can even do it with default 20/20 theme. Jan 8, 2011 at 5:28
  • Alexandre, How do I tell PHP to add a style sheet? Don't those have to be specified in the Header of the page? Jan 17, 2011 at 23:40
  • Yes, it needs to be in a header of the page. But single.php is a full page. Worst case, make it a copy of default.php (which has full functionality) and just add your extra include in the appropriate area. Jan 21, 2011 at 0:38

There are several ways to approach this, mostly depending on how major changes in styling are going to be:

  • filter output of body_class() function (or wait for 3.1 in which according to docs terms are going to be included automatically) and including style differences in your main stylesheet;
  • echo additional styling inline (preferably when amount is minimal);
  • load additional stylesheets.

See Conditional Tags for how to check for different stuff and wp_enqueue_style() for loading additional stylesheets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.