Site logo

Archived topic

Custom CSS Classes and generate_do_element_classes()

5 replies · Started by Stephane Bergeron on January 3, 2019

Viewing posts 1–6 of 6

Hi,

The new generate_do_element_classes() has been added in GP 2.2. I never used the previous functions this replaces so I don't know where to start looking for them to see how I might use the new one.

What I'm trying to do is add an additional CSS class to the main element in WooCommerce shop pages (it's for FacetWP). In Genesis, I would use this:

add_filter( 'genesis_attr_content', 'zw3_main_content_add_class' );
function zw3_main_content_add_class( $attributes ) {

	// add original plus extra CSS classes
	if( is_shop() ) {
		$attributes['class'] .= ' facetwp-template';
	}

	// return the attributes
	return $attributes;

}

This is a specific filter to target the specific element but you get the idea. How can I achieve the same in GP with generate_do_element_classes?

Thanks!

Hi there,

In GP, you would do this:

add_filter( 'generate_main_class', function( $classes ) {
    if ( function_exists( 'is_shop' ) && is_shop() ) {
        $classes[] = 'facetwp-template';
    }

    return $classes;
} );

Let me know :)

Thanks Tom! Works great of course :)

But I see that, like Genesis, it seems to be a specifically named filter. Is there a list of them in the docs somewhere. Of course, if they are all named as obviously as this one, I can infer pretty much any other ;)

Can never have too many details in the docs :)

Thank you very much!!

You're welcome :)

This archived topic is closed to new replies.