Add The Category and Page Title to Pages As Body Classes

Posted on 21st September, 2015 449 Comments

To add some custom styles to individual category pages you can use this snippet to add a body class to our posts.

functions.php

/* 
 * ADD CATEGORY AND PAGE TITLE TO PAGES AS CLASSES
 *************************************************************/
 
function add_slug_body_class( $classes ) {
	
	// Grab the page title
	global $post;
	if ( isset( $post ) ) {
		$classes[] = $post->post_type . '-' . $post->post_name;
	}
	
	// Grab the category
	if ( is_single() && !is_front_page() && !is_home() )
		return $classes;
	$post_categories = get_the_category();
	foreach( $post_categories as $current_category ) {
		$classes[] =  $current_category->slug; 
	}
	return $classes;
}
add_filter( 'body_class', 'add_slug_body_class' );

Comments

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]

Durekbah

09th, Oct, 20

Beneficial information. With thanks! scholarship essay writing [url=https://discountedessays.com/]writing help[/url] proquest dissertations search

Durekbah

09th, Oct, 20

Wonderful content. Many thanks. best website to get essays [url=https://englishessayhelp.com/]cheap essay writing services[/url] thesis degree

MelviFug

12th, Oct, 20

You made the point.
canadian pharmacy viagra brand [url=https://canada21health.com/]board of pharmacy[/url] meds online

DwayneDethy

12th, Oct, 20

With thanks, I appreciate it. aarp approved canadian online pharmacies [url=https://canadianmsnpharmacy.com/]canada pharmaceuticals online[/url] discount drugs online pharmacy

Durekbah

14th, Oct, 20

Good info. Kudos! help with essays assignments [url=https://paperwritingservicestops.com/]essays writing service[/url] write your dissertation

MelviFug

14th, Oct, 20

Thanks a lot, Excellent stuff!
internet pharmacy [url=https://canadianpharmaciesmsn.com/]canadian online pharmacies[/url] cialis online

Direkbah

14th, Oct, 20

Very good forum posts. Cheers! writing argumentative essays [url=https://theessayswriters.com/]homework hotline[/url] phd dissertation length

DwayneDethy

15th, Oct, 20

Fine content. Appreciate it! canadian pharmacies that are legit [url=https://canadianpharmaceuticalsrx.com/]legal canadian prescription drugs online[/url] londondrugs

MelviFug

16th, Oct, 20

Factor certainly regarded!.
canada pharma limited [url=https://canada21health.com/]northwest pharmacy[/url] canadian pharmacy no prescription

Durekbah

17th, Oct, 20

Fine knowledge. Cheers! how to write an essay for scholarship [url=https://scoringessays.com/]essay writing service[/url] social science dissertation

DwayneDethy

18th, Oct, 20

Superb data. Regards! canada pharmaceuticals [url=https://canadianonlinepharmacyhere.com/]canada drug[/url] canadian pharcharmy online fda approved

JamesVen

21st, Oct, 20

how unreal it can be to do your pasty diagnostics [url=https://ciamedusa.com/#]cheapest cialis[/url] of complete from your serene to liberal the introductory amount.

Durekbah

05th, Nov, 20

Appreciate it. Plenty of data.
compare and contrast college essay [url=https://writingthesistops.com/]dissertations[/url] uk dissertation help

Direkbah

06th, Nov, 20

You made your position quite nicely!. writing a research essay [url=https://topswritingservices.com/]write my essay[/url] dissertation

viagra online prices

07th, Nov, 20

While the program will require a little bit of preparation to enter, you will earn a complete and
fast paced education that will prepare you to move up in your chosen field.
viagra online prices buy viagra online
without prescription

Durekbah

08th, Nov, 20

Wow quite a lot of fantastic data! type of essays writing [url=https://englishessayhelp.com/]help in thesis writing[/url] phd thesis cover page

Direkbah

09th, Nov, 20

Useful tips. Kudos. how to write a self evaluation essay [url=https://essayextra.com/]essay typer[/url] thesis or dissertation

Durekbah

10th, Nov, 20

Thanks a lot. Wonderful stuff! how to write an amazing essay [url=https://discountedessays.com/]write paper[/url] writing a good dissertation

Direkbah

11th, Nov, 20

Whoa all kinds of excellent information. how to write an essay essay [url=https://scoringessays.com/]couseworks[/url] writing a dissertation

Ac repair

12th, Nov, 20

Normally I don’t read post on blogs, but I wish to say that this write-up very forced me to try and do so! Your writing style has been amazed me. Thanks, very nice post.

Durekbah

13th, Nov, 20

You actually said that really well! college essay music [url=https://topessayssites.com/]writing dissertation[/url] how to write dissertation

BrianTat

17th, Nov, 20

Wonderful posts. Many thanks.

How Long For Provigil To Work [url=https://topmodafinilrxpills.com/]modafinil side effects[/url]

Deidra Gandrud

19th, Nov, 20

I used to be more than happy to search out this web-site.I wished to thanks for your time for this wonderful learn!! I undoubtedly enjoying every little little bit of it and I’ve you bookmarked to take a look at new stuff you blog post.

Durekbah

19th, Nov, 20

You said it very well.! issues to write about in a college essay [url=https://discountedessays.com/]write papers[/url] the essay

you can try here electrician

02nd, Dec, 20

Just wish to say your article is as surprising. The clearness in your post is just excellent and i can assume you’re an expert on this subject. Fine with your permission let me to grab your feed to keep updated with forthcoming post. Thanks a million and please continue the enjoyable work.

important site electrical repair san diego

03rd, Dec, 20

We’re a group of volunteers and opening a new scheme in our community. Your website provided us with useful information to paintings on. You have done a formidable task and our whole community will likely be grateful to you.

hey

05th, Jan, 21

Taxi moto line
128 Rue la Boétie
75008 Paris
+33 6 51 612 712  

Taxi moto paris

Attractive portion of content. I just stumbled upon your blog and in accession capital to assert that I acquire in fact loved account your weblog posts.
Anyway I will be subscribing on your feeds or even I
success you get entry to consistently rapidly.

Bennett Buonaiuto

08th, Jan, 21

I live in Costa Rica and am about to publish a community newspaper, what are the steps to go about copyrighting the name and articles published in it? And also when can one start using the copyright symbol?.

vreyrolinomit

09th, Jan, 21

I like what you guys are up too. Such smart work and reporting! Carry on the superb works guys I have incorporated you guys to my blogroll. I think it’ll improve the value of my website :).

phishing

10th, Jan, 21

Hi, I do believe this is a great blog. I stumbledupon it 😉 I may return once again since i have book marked it.
Money and freedom is the greatest way to change, may you be rich and continue to guide
others.

vreyrolinomit

19th, Jan, 21

A person necessarily help to make severely articles I might state. That is the first time I frequented your web page and to this point? I surprised with the research you made to create this particular publish incredible. Wonderful process!

Lcxeloks

19th, Jan, 21

where to buy viagra singapore viagra syd viagra\\\’ [url=http://genqpviag.com/]which one is better viagra cialis or laverta[/url] ’

WilsonSetle

20th, Jan, 21

chloroquine amazon
[url=https://chloroquineorigin.com/#]aralen for sale[/url]
when erectile dysfunction meds quite working
[url=https://erectiledysfunctionbjul.com/#]can erectile dysfunction be prevented[/url]
hydroxyquine drug
[url=https://hydroxychloroquinex.com/#]azathioprine[/url]
erectile potion
[url=https://plaquenilx.com/#]plaquenil classification[/url]
elevex tadalafil 20mg
[url=https://tadalisxs.com/#]tadalafil generic[/url]
zithromax medication
[url=https://zithromaxes.com/#]zithromax antibiotic without prescription[/url]

viagra pro nfjnzo

23rd, Jan, 21

viagra prescription online [url=http://www.canada1drugstore.com/tadalafil/]over the counter viagra[/url] natural alternative to viagra
canada meds natural substitute for viagra

zortilo nrel

25th, Jan, 21

F*ckin’ awesome things here. I’m very glad to see your post. Thanks a lot and i am looking forward to contact you. Will you kindly drop me a mail?

cheap flights

29th, Jan, 21

I for all time emailed this blog post page to all my friends, for
the reason that if like to read it next my contacts will too.

cheap flights

29th, Jan, 21

Great goods from you, man. I’ve understand your stuff previous to and
you’re just extremely magnificent. I actually like what you’ve acquired here, really like what you’re stating and the
way in which you say it. You make it entertaining and you still care for to keep it
wise. I can’t wait to read much more from you. This is actually
a great web site.

vreyro linomit

31st, Jan, 21

But wanna comment on few general things, The website design is perfect, the content material is very great. “Believe those who are seeking the truth. Doubt those who find it.” by Andre Gide.

KbbgBoth

31st, Jan, 21

how much is a viagra prescription with no insurance Viagra viagra viagra combo [url=http://erectilejyzd.com/]Yasmin[/url] ’

tinyurl.com

02nd, Feb, 21

These are really impressive ideas in on the topic of blogging.
You have touched some good factors here. Any way keep up wrinting.

LEmethypsype

02nd, Feb, 21

du therapies breves lyon, pharmacie amiens super u pharmacie amiens gambetta pharmacie pasteur aix en provence horaires, pharmacie berrichonne bourges pharmacie avignon mistral 7 therapie comportementale cognitive gard pharmacie leclerc la roche sur yon therapie de couple comment Г§a se passe pharmacie de garde yutz , pharmacie en ligne ordonnance pharmacie leclerc falaise , https://tinyurl.com/y6fnuw5l# pharmacie leclerc vern pharmacie de garde avignon numero [url=https://u.to/Uon7Gg#]Order Metformin online[/url] , pharmacie ouverte joue les tours pharmacie de garde aujourd’hui yopougon , [url=https://www.insurances.net/viewthread.php?tid=2278414&pid=40731668&page=1&extra=#pid40731668]community acquired pneumonia microbiology stuff[/url] f00a83b pharmacie jayez amiens. pharmacie intermarche nord beauvais pharmacie fauquet amiens [url=https://u.to/qfX7Gg#]Buy Prednisone generic cheap[/url] , pharmacie aix en provence de garde pharmacie ouverte quincy sous senart , medicaments qui constipent.

gidrasajt4afgake

03rd, Feb, 21

gidrasajt4af.com представляет из себя ресурс, что придуман для продавцов незаконных вещей и сервисов. Такую же продукцию неприлично достать в нормальном интернет-магазине, потому что это неправомерно.

tinyurl.com

12th, Feb, 21

Now I am going to do my breakfast, afterward having my breakfast coming yet again to read additional news.

Ibacroli

12th, Feb, 21

recall on blood pressure medication 2018 – viagra generic Yeivnmy
cialis amazing
turn on liquid viagra: [url=https://www.withoutbro.com/]is there a generic for viagra[/url]

froleprotrem

16th, Feb, 21

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post…

shell priv8 download

18th, Feb, 21

I do not know if it’s just me or if everyone else experiencing issues with your site.
It appears like some of the written text on your content are running off the screen. Can somebody else please comment and let
me know if this is happening to them too? This might be a issue
with my browser because I’ve had this happen before.
Thank you

sepesuimb

20th, Feb, 21

used eileen plater dresses order red wing shoes 875 [url=http://www.222book222.com]per cover sassy pants blue lamb [/url]
soceress renasaince dress jockey panties pictures <a href=”http://www.452href.com”> badger tee shirt </a>
roy mercer wooden shoes 1940 s dancing dresses http://www.udwcs1223.com pali shoes mn

sepesuimb

20th, Feb, 21

beck’s beer shirt pixma print on t shirts [url=http://www.222book222.com]sheep beer t shirt [/url]
babies club feet shoes old friend relfex massage shoes <a href=”http://www.452href.com”> paper t shirt activity </a>
size 8 underwear women’s running shoes for supinators http://www.udwcs1223.com dress code for church choirs

Google

25th, Feb, 21

Google

Here is an excellent Weblog You might Obtain Intriguing that we encourage you to visit.

Cheap Twitter Services

26th, Feb, 21

My partner and I stumbled over here coming from a different web address and thought I may as well check things out. I like what I see so i am just following you. Look forward to looking into your web page repeatedly.

Dingdong Togel Online

27th, Feb, 21

Heya fantastic blog! Does running a blog similar to this require a lot of work?

I’ve absolutely no expertise in coding but I was hoping to start my own blog in the near future.
Anyhow, if you have any recommendations or techniques for new blog owners please share.
I know this is off topic nevertheless I simply wanted to ask.
Kudos!

Cheap Social Media Plays

27th, Feb, 21

Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your weblog? My website is in the exact same area of interest as yours and my users would truly benefit from a lot of the information you provide here. Please let me know if this ok with you. Thanks a lot!

tadalafil no prescription needed

28th, Feb, 21

Hey there just wanted to give you a quick
heads up. The words in your content seem to be running
off the screen in Chrome. I’m not sure if this
is a format issue or something to do with internet browser compatibility but
I figured I’d post to let you know. The style and design look great though!
Hope you get the issue fixed soon. Cheers https://cialis.webbfenix.com/tadalafil

dapoxetine 90mg

06th, Mar, 21

I’ve been exploring for a bit for any high quality
articles or weblog posts on this sort of house .
Exploring in Yahoo I at last stumbled upon this web site.

Reading this information So i am satisfied to exhibit
that I’ve an incredibly just right uncanny feeling I came upon just
what I needed. I so much unquestionably will make certain to
do not disregard this site and provides it a glance on a continuing basis. http://herreramedical.org/dapoxetine

우리카지노

08th, Mar, 21

우리카지노

[…]that would be the finish of this post. Right here you will come across some internet sites that we believe you’ll enjoy, just click the links over[…]

Outsourcing Agency

12th, Mar, 21

Outsourcing Agency

[…]check below, are some entirely unrelated sites to ours, having said that, they are most trustworthy sources that we use[…]

safestore auto

13th, Mar, 21

safestore auto

[…]just beneath, are numerous absolutely not connected internet sites to ours, nonetheless, they may be certainly really worth going over[…]

laptop app

14th, Mar, 21

laptop app

[…]that would be the end of this report. Here you will come across some internet sites that we think you’ll enjoy, just click the hyperlinks over[…]

Buy Opana Online

23rd, Mar, 21

Buy Opana Online

[…]Wonderful story, reckoned we could combine a number of unrelated data, nonetheless truly really worth taking a appear, whoa did a single learn about Mid East has got more problerms also […]

psilocybe cubensis grow kit usa

24th, Mar, 21

psilocybe cubensis grow kit usa

[…]that may be the finish of this post. Right here you’ll discover some web pages that we think you will enjoy, just click the hyperlinks over[…]

Curso escala pentatônica

26th, Mar, 21

Curso escala pentatônica

[…]we prefer to honor several other world wide web web pages around the internet, even though they aren’t linked to us, by linking to them. Beneath are some webpages worth checking out[…]

click here

30th, Mar, 21

click here

[…]Every the moment inside a while we select blogs that we read. Listed beneath would be the most up-to-date web pages that we select […]

logo design jona

30th, Mar, 21

logo design jona

[…]just beneath, are various entirely not connected websites to ours, even so, they’re certainly really worth going over[…]

Herbal incense

31st, Mar, 21

Herbal incense

[…]here are some hyperlinks to web sites that we link to because we feel they’re worth visiting[…]

Canada Pharmacy

03rd, Apr, 21

Canada Pharmacy

[…]very couple of web sites that take place to be comprehensive beneath, from our point of view are undoubtedly nicely worth checking out[…]

Boldenone Acetate Powder

04th, Apr, 21

Boldenone Acetate Powder

[…]Wonderful story, reckoned we could combine a few unrelated information, nevertheless really really worth taking a search, whoa did one particular learn about Mid East has got more problerms too […]

virtual card buy

05th, Apr, 21

virtual card buy

[…]although internet sites we backlink to beneath are considerably not associated to ours, we really feel they are truly worth a go by, so have a look[…]

bare copper wire

06th, Apr, 21

bare copper wire

[…]Every once in a when we select blogs that we read. Listed below are the most up-to-date web sites that we pick out […]

cbd oil for sale ireland

06th, Apr, 21

cbd oil for sale ireland

[…]that would be the finish of this report. Right here you’ll obtain some web sites that we feel you will enjoy, just click the links over[…]

swap bot

08th, Apr, 21

swap bot

[…]we came across a cool web page that you just might delight in. Take a look in case you want[…]

delta 8 THC for sale

09th, Apr, 21

delta 8 THC for sale

[…]Every once inside a even though we pick out blogs that we read. Listed beneath are the most recent web-sites that we decide on […]

delta 8 THC near me

09th, Apr, 21

delta 8 THC near me

[…]very couple of internet websites that come about to be comprehensive below, from our point of view are undoubtedly effectively really worth checking out[…]

Services

11th, Apr, 21

Services

[…]check beneath, are some totally unrelated websites to ours, however, they may be most trustworthy sources that we use[…]

order guns online

11th, Apr, 21

order guns online

[…]here are some hyperlinks to web-sites that we link to simply because we think they’re worth visiting[…]

샌즈카지노

12th, Apr, 21

샌즈카지노

[…]very few websites that transpire to be detailed beneath, from our point of view are undoubtedly well really worth checking out[…]

Lakia Mowles

14th, Apr, 21

When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four e-mails with the same comment. Is there any way you can remove me from that service? Many thanks!

Cardano (ADA)

15th, Apr, 21

Cardano (ADA)

[…]usually posts some pretty fascinating stuff like this. If you are new to this site[…]

taurus g2c

17th, Apr, 21

taurus g2c

[…]one of our guests a short while ago recommended the following website[…]

buy guns online

17th, Apr, 21

buy guns online

[…]Every when in a although we select blogs that we study. Listed beneath are the most recent web sites that we choose […]

siamese kittens for sale near me

17th, Apr, 21

siamese kittens for sale near me

[…]Wonderful story, reckoned we could combine several unrelated information, nonetheless definitely worth taking a appear, whoa did a single master about Mid East has got a lot more problerms at the same time […]

Leave a Comment

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]