Welcome to WebmasterWorld Guest from 54.157.225.99

Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

Add class to category Wordpress

wordpress add class

     
7:28 pm on Apr 16, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:June 23, 2009
posts: 42
votes: 0


I want to add a class to my css if a category is displayed but I can't get it to work.

I added this to my header:

<?php if ( is_category('areas')) { echo ' class="myclass" '; } ?>>

I want to add this class to my stylesheet to any page in this category so It changes the look of any page in that category. It isn't working though.

Ive read through a lot of the codex and this is all I can figure to do

Any suggestions?
Rob
7:30 pm on Apr 16, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7575
votes: 0


is_category only works for the category level page itself. Use in_category for anything within that category so:

is_category('areas') || in_category('areas')
11:31 pm on Apr 16, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:June 23, 2009
posts: 42
votes: 0


Thank you so much that is exactly what I needed.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members