• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Adding a custom body class to several category archives

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding a custom body class to several category archives

This topic is: resolved

Tagged: category archive, custom body class

  • This topic has 8 replies, 2 voices, and was last updated 10 years, 4 months ago by Gina.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • February 23, 2015 at 11:45 am #141886
    Gina
    Member

    I cannot figure out how to add a custom body class to more than one category archive. I have a website that has two different styles to the navigation...one part gold, the other blue with a secondary nav. So all of the gold portion is styled and working fine. All of the blue portion is styled correctly except for the category archives. I can get one category archive navigation styled correctly. I also found the following code that will allow me to add a custom body class (same one I'm using for pages in the blue section) to ONE category archive but for some reason I am unable to add it to more than one.

    /* add a custom body class */
    add_action( 'body_class', 'ilwp_add_my_bodyclass');
    function ilwp_add_my_bodyclass( $classes ) {
    if ( is_category( 'parish-plan' ))
    $classes[] = 'hsep';
    return $classes;
    }

    Anyone know how I can add the body class hsep to more than one category archive?

    http://plaqueminesparish.com/wp/category/homeland-security/parish-plan/
    February 23, 2015 at 11:52 am #141887
    Gina
    Member

    I finally found the answer to this question! I've been trying to figure this out for days 🙂
    For multiple categories the below works:

    /* add a custom body class */
    add_action( 'body_class', 'ilwp_add_my_bodyclass');
    function ilwp_add_my_bodyclass( $classes ) {
    if ( is_category( array(parish-plan,residential-emergency-planning,business-emergency-planning,evacuation-guidelines) ) ) { echo 'hi'; }
    $classes[] = 'hsep';
    return $classes;
    }

    You can enter the category id instead if you don't have the parent category name inside the body tag.

    February 23, 2015 at 2:12 pm #141907
    Gina
    Member

    So I almost have this resolved 🙂

    I added the add action as stated above and it worked EXCEPT it added it to two categories that I did not include and do not want it to be added to: latest-news and upcoming-events.

    I'm not sure why it did that. I tried adding an else if but I don't have all of the syntax correct. Can someone please help!!!!

    February 23, 2015 at 3:16 pm #141917
    Brad Dalton
    Participant

    Hard to test the code you pasted as its not wrapped in pre or code tags so it breaks when added to the functions file.

    Also, where did you get the code from? Please link to the source.


    Tutorials for StudioPress Themes.

    February 23, 2015 at 6:44 pm #141948
    Gina
    Member

    I have replied to this twice. Are you getting them? I don't see them on this page so wasn't sure 🙂

    February 23, 2015 at 6:46 pm #141949
    Gina
    Member

    Well since that one displays I will try this again...

    Thank you for your reply! This is where I found the code: http://ilikewp.com/how-to-add-a-custom-body-class/

    Here is the code as requested sorry about that:

    /* add a custom body class */ 
    add_action( 'body_class', 'ilwp_add_my_bodyclass'); 
    function ilwp_add_my_bodyclass( $classes ) { 
     if ( is_category( array(parish-plan,residential-emergency-planning,business-emergency-planning,evacuation-guidelines) ) ) 
       $classes[] = 'hsep'; 
     return $classes; 
    }
    February 23, 2015 at 6:47 pm #141950
    Gina
    Member

    Here is the code as requested:

    /* add a custom body class */ 
    add_action( 'body_class', 'ilwp_add_my_bodyclass'); 
    function ilwp_add_my_bodyclass( $classes ) { 
     if ( is_category( array(parish-plan,residential-emergency-planning,business-emergency-planning,evacuation-guidelines) ) ) 
       $classes[] = 'hsep'; 
     return $classes; 
    }

    The link where I got it from will not post for some reason. It was in an article titled "How To Add a Custom Body Class" on the I Like WordPress blog.

    February 23, 2015 at 6:49 pm #141954
    Gina
    Member

    I got it from ilikewp.com/how-to-add-a-custom-body-class

    February 24, 2015 at 9:14 am #142022
    Gina
    Member

    So it's been pointed out that I don't have the category names in quotes. Once I did that it fixed the problem.

    /* add a custom body class */ 
    add_action( 'body_class', 'ilwp_add_my_bodyclass'); 
    function ilwp_add_my_bodyclass( $classes ) { 
     if ( is_category( array('parish-plan','residential-emergency-planning','business-emergency-planning','evacuation-guidelines') ) ) 
       $classes[] = 'hsep'; 
     return $classes; 
    }
  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble