{"id":2437,"date":"2022-07-02T17:09:53","date_gmt":"2022-07-02T17:09:53","guid":{"rendered":"https:\/\/academy.bricksbuilder.io\/?post_type=bricks_article&p=2437"},"modified":"2022-07-25T10:02:28","modified_gmt":"2022-07-25T10:02:28","slug":"filter-bricks-set_root_attributes","status":"publish","type":"bricks_article","link":"https:\/\/academy.bricksbuilder.io\/article\/filter-bricks-set_root_attributes\/","title":{"rendered":"Filter: bricks\/element\/set_root_attributes"},"content":{"rendered":"\n
Bricks 1.4 with its improved & slimmer DOM structure now requires to add the element ID, root classes, and other element root HTML attributes directly inside the The filter callback receives 2 arguments:<\/p>\n\n\n\nrender()<\/code> function. You can programmatically manipulate the returns element root attributes like so:<\/p>\n\n\n\n
add_filter( 'bricks\/element\/set_root_attributes', function( $attributes, $element ) {\n \/\/ Add CSS class 'heading-bg' to every heading element\n if ( $element->name === 'heading' ) {\n $attributes['class'][] = 'heading-bg'; \n }\n\n return $attributes;\n}, 10, 2 );<\/code><\/pre>\n\n\n\n
$attributes<\/code>\u00a0\u2013 an associative array of the element root attributes, grouped by the attribute name (e.g. “class”, “data-animation”, …)<\/li>
$element<\/code> – the Bricks element object<\/a><\/li><\/ul>\n\n\n\n