Community Forums › Forums › Archived Forums › General Discussion › Multiple body classes ignored for CPT
Tagged: body class, custom body class
- This topic has 10 replies, 3 voices, and was last updated 9 years ago by
simbasounds.
-
AuthorPosts
-
September 20, 2014 at 2:04 pm #125161
simbasounds
MemberUsing 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 #125171Brad Dalton
ParticipantIs 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
September 20, 2014 at 4:09 pm #125173simbasounds
MemberThanks 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 #125176Brad Dalton
ParticipantThink its an old loop hook so i assume you're running XHTML markup?
September 20, 2014 at 5:19 pm #125177simbasounds
MemberOk, 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 enterfullwidth sideheader
it adds a body class of fullwidthsideheader.
I also triedfullwidth%20sideheader
and evenfullwidth %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 #125179simbasounds
MemberNo, 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 #125197simbasounds
MemberI 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:
As shown in this screenshot of the source of the archive page it's concatenating the classes:
I'll contact support and see what they say..
September 22, 2014 at 3:09 am #125280Gary Jones
MemberAt 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 #125282simbasounds
MemberThanks 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 #125283Gary Jones
Membergenesis/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 #125284simbasounds
MemberThanks, will give it a go..
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.