Adding Attributes to Elements via assigned global class?

Hey Bricks Fam,

We’re using the Set Root Attributes to Bricks elements and wanted to see if anyone has figured out if it’s possible to target Bricks elements based on which global class is assigned?

For instance, we want to target all Header elements that have global class “.hero-secondary__header” as the assigned class and add a data-attribute.

Is this possible?

Filter: bricks/element/set_root_attributes – Bricks Academy

Anyone online familiar with this?

add_filter( 'bricks/element/set_root_attributes', function( $attributes, $element ) {
	if ( in_array( 'test-class', $attributes['class'] ) ) {
		$attributes['data-header-type'] = 'shrinking'; 
	}

	return $attributes;
}, 10, 2 );
3 Likes

Hi @Sridhar - This is great! Thanks for responding to my Brickslab question and creating the new tutorial. Bricks’ Official documentation does not provide all of the available element/object syntax so this is super helpful.

Works great for targeting many similar elements, without manually applying attributes post-dev :slight_smile: