• 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

Multiple body classes ignored for CPT

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 › General Discussion › Multiple body classes ignored for CPT

This topic is: not resolved

Tagged: body class, custom body class

  • This topic has 10 replies, 3 voices, and was last updated 9 years ago by simbasounds.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • September 20, 2014 at 2:04 pm #125161
    simbasounds
    Member

    Using this as my functions.php for portfolio CPT with archive settings support, and this as my archive-portfolio.php, everything is working great.

    But there seems to be a bug: if I enter more than one body class in the Archive Settings, then no custom body classes are not output to the front end at all. (As a long-shot I tried fiddling with spaces, periods and commas. It should work with space separators).

    Multiple body classes work as per usual on normal pages, posts and single portfolio CPTs.

    I can get around it by creating a single extra combined class with the CSS attributes from both classes, but it's not ideal.

    September 20, 2014 at 3:43 pm #125171
    Brad Dalton
    Participant

    Is this a valid hook?

    genesis_after_entry_content
    

    Also, you can add custom body classes from your functions file or directly in each template:

    add_filter( 'body_class', 'executive_add_portfolio_body_class' );
    function executive_add_portfolio_body_class( $classes ) {
       $classes[] = 'executive-pro-portfolio';
       return $classes;
    }
    

    Also, you're dding support for gss here

    add_action ('init', 'portfolio_sidebars_support');
    function portfolio_sidebars_support() {
    	add_post_type_support( 'portfolio', 'genesis-simple-sidebars' );
    }
    

    and also in the CPT function

     'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail', 'trackbacks', 'revisions', 'custom-fields', 'post-formats', 'genesis-seo', 'genesis-cpt-archives-settings', 'genesis-simple-sidebars',),
    

    Plus you have a comma at the end before the closing bracket that's not needed.

    Better to use codefrom Genesis for your CPT


    Tutorials for StudioPress Themes & WooCommerce.

    September 20, 2014 at 4:09 pm #125173
    simbasounds
    Member

    Thanks so much for the thorough analysis of my code, Brad - very much appreciated.
    Will try a few things and see what works, then report back here.

    re. genesis_after_entry_content - it's mentioned here

    September 20, 2014 at 5:18 pm #125176
    Brad Dalton
    Participant

    Think its an old loop hook so i assume you're running XHTML markup?


    Tutorials for StudioPress Themes & WooCommerce.

    September 20, 2014 at 5:19 pm #125177
    simbasounds
    Member

    Ok, I've cleaned it all up, including using the simpler CPT code.

    Looking more closely it seems that the problem is that for CPT archives it removes the space between classes.
    So if I enter fullwidth sideheader it adds a body class of fullwidthsideheader.
    I also tried fullwidth%20sideheader and even fullwidth %20 sideheader, but it still removes the encoded space.

    It's not ideal, but if there's no obvious fix I'm happy to use work-arounds.

    September 20, 2014 at 5:24 pm #125179
    simbasounds
    Member

    No, HTML5. I think the hook is fine. I've been using it on many of my sites.
    I tried changing it to genesis_entry_content to see if it has anything to do with that body class space bug, but the bug remained.

    September 21, 2014 at 4:46 am #125197
    simbasounds
    Member

    I set up a test site with default Genesis + Genesis Sample child theme.
    I used the members CPT code with support for 'genesis-cpt-archives-settings'.

    After updating permalinks I added two body classes to the archive settings:
    Screenshot of Custom Body Class used on CPT archive

    As shown in this screenshot of the source of the archive page it's concatenating the classes:
    Screenshot of page source with body class concatenation

    I'll contact support and see what they say..

    September 22, 2014 at 3:09 am #125280
    Gary Jones
    Member

    At this moment in time, what you're seeing is intended behaviour. If you want to add multiple classes, you'll need to filter them in with code, not the UI.

    However, I will make a suggestion to core developers that space-separation of multiple class is supported.


    WordPress Engineer, and key contributor the Genesis Framework | @GaryJ

    September 22, 2014 at 3:40 am #125282
    simbasounds
    Member

    Thanks Gary. It seems more logical to me that multiple classes should be supported for CPT archives since they are supported for single CPTs and standard WordPress pages and single posts.

    My intended usage was to give users of a child theme or Dynamik skin the option of tagging any page, post, single CPT or archive certain functionality like full-width-page or sidebar-header, or both, by using body classes. So far I'm working around it by making extra combined classes with combined attributes, so there's no urgency.

    September 22, 2014 at 4:05 am #125283
    Gary Jones
    Member

    genesis/lib/structure/layout.php, around line 176, you should see:

    $classes[] = esc_attr( sanitize_html_class( $new_class ) );

    inside a function called genesis_cpt_archive_body_class. Can you please change that line to:

    $classes[] = esc_attr( $new_class );

    And see if that fixes the problem?


    WordPress Engineer, and key contributor the Genesis Framework | @GaryJ

    September 22, 2014 at 4:09 am #125284
    simbasounds
    Member

    Thanks, will give it a go..

  • Author
    Posts
Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘General Discussion’ 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

© 2023 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