Support is closed now. We shall check all on 20th May 2024.

Premium add-on for Bricks Builder

Adding Custom Class To Heading Element’s Anchor Tag

Original request:

Hi! Is it possible to add a custom class directly in the <a> tag instead of the parent element?

Bricks have filter bricks/element/render_attributes. You can add a custom attribute(s) to the element with this filter and the custom PHP code. Open the functions.php file of the Bricks child theme or add the code to the 3rd party snippets plugin.

add_filter( 'bricks/element/render_attributes', 'bu_render_attributes', 10, 3 );
function bu_render_attributes( $attributes, $key, $el_instance ) {
	if( $el_instance->name == 'heading' && $el_instance->id == 'yfsqjl' && $key == 'a' ) {
		$attributes['a']['class'][] = 'custom-class';
	}

	return $attributes;
}

yfsqjl is the ID of my Heading element. You will replace it with your element ID if you are targeting a specific element. Otherwise, it will apply to the entire site’s Heading <a> tag. Replace custom-class with your CSS classname.

Fills In: 

Leave the first comment

Search Tutorials

Request TutorialsFeatures Request