Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Header configuration & styling (http://forum.bytesforall.com/forumdisplay.php?f=15)
-   -   [SOLVED] Add a Post’s Category Name to Body Class (http://forum.bytesforall.com/showthread.php?t=19686)

johnnybravo Feb 20, 2013 11:28 PM

[SOLVED] Add a Post’s Category Name to Body Class
 
Hi from Russia.
How to Add a Post’s Category Name to Body Class?
I need it for customize menu.
I found only this example:
Code:

function add_category_name($classes = '') {
  if(is_single()) {
      $category = get_the_category();
      $classes[] = 'category-'.$category[0]->slug;
  }
  return $classes;
}
add_filter('body_class','add_category_name');

Can this code help me? Where i have to insert this code? functions.php?

juggledad Feb 21, 2013 02:40 AM

Where did the place you found the code snippet suggest you put it?
Did you try it?

johnnybravo Feb 21, 2013 03:22 AM

Here
I did not try, because I do not know where to insert this code.

juggledad Feb 21, 2013 03:41 AM

That link tells you where to put the snippet.

johnnybravo Feb 21, 2013 04:22 AM

Thanks!!! It works!!! Now in body classes i can see class - "category-name" and in css i added some style for this category. Cool!!!


All times are GMT -6. The time now is 10:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.