Site logo

Archived topic

Kopfbereich / Pagehero class

9 replies · Started by Jochen on January 27, 2023

Viewing posts 1–10 of 10

Hey,

I have two different Headers. One in a light version and another in dark.
I gave one of them an element class „menu-light“ which is not added to the header.

What can I do here? I don't want to change to block elements.

Best regards
J

Hi Jochen,

I don't think I understand your question.

Can you share more details and links?

Hi there,

what are the Display Rules you're using to set which Header Element is displayed?
As we would need to add a CSS class to the body to make that work.

So the display rule is set as below?

1. Front page
2. Blog
3. Post > all posts
4. Page > impressum

Can you link us to the impressum page?

Hey,

the project is wip and password protected.
I send the info via private information.

Try adding this PHP Snippet to your site:

add_filter( 'body_class', function( $classes ) {
    global $generate_elements;
    foreach ( $generate_elements as $element => $data ) {
        $element_title = 'gp-elem-' . strtolower(str_replace(' ', '-', get_the_title( $data['id'] ) ));
        $classes[] = $element_title;
    }
    return $classes;
});

In the body tag it will print a class like so: gp-elem-{elements-title} for each element on the page.
For example i create an element titled: menu-light
Then it will print a class: gp-elem-menu-light that you can use in your CSS.

Hey David,

thank you very much. It works now!

Best regards
Jochen

Glad to hear that!

This archived topic is closed to new replies.