{"id":2127,"date":"2021-12-16T18:48:24","date_gmt":"2021-12-16T18:48:24","guid":{"rendered":"https:\/\/academy.bricksbuilder.io\/?post_type=bricks_article&p=2127"},"modified":"2022-08-10T10:43:58","modified_gmt":"2022-08-10T10:43:58","slug":"filter-bricks-element-render_attributes","status":"publish","type":"bricks_article","link":"https:\/\/academy.bricksbuilder.io\/article\/filter-bricks-element-render_attributes\/","title":{"rendered":"Filter: bricks\/element\/render_attributes"},"content":{"rendered":"\n

Starting with Bricks 1.3.7 you may manipulate the HTML <\/strong>attributes of a given element using the following filter:<\/p>\n\n\n\n

add_filter( 'bricks\/element\/render_attributes', function( $attributes, $key, $element ) {\n    if ( isset( $element->settings['my_setting'] ) \n       && $element->settings['my_setting'] == 'xpto' ) {\n        $attributes[ $key ]['data-xpto'] = 'my data';\n    }\n    \n    return $attributes;\n}, 10, 3 );<\/code><\/pre>\n\n\n\n

The filter callback receives 3 arguments:<\/p>\n\n\n\n

  • $attributes<\/code> – an associative array of the element attributes, grouped by the $key identifier <\/li>
  • $key<\/code> – the HTML element identifier to render attributes for<\/li>
  • $element<\/code> – the Bricks element object (since Bricks 1.5)<\/li><\/ul>\n\n\n\n

    Since Bricks 1.4, if you need to get access to the $is_frontend<\/code> value (whether the element is rendering in the frontend or in the builder), please use the global function bricks_is_frontend()<\/code>.<\/p>\n\n\n\n

    Since Bricks 1.5, the $settings<\/code> and $name<\/code> arguments are deprecated. You may use the callback 3rd argument to get those: $element->settings<\/code> and $element->name<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"

    Starting with Bricks 1.3.7 you may manipulate the HTML attributes of a given element using the following filter: The filter callback receives 3 arguments: $attributes – an associative array of the element attributes, grouped by the $key identifier $key – the HTML element identifier to render attributes for $element – the Bricks element object (since […]<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":102,"template":"","format":"standard","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article\/2127"}],"collection":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article"}],"about":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/types\/bricks_article"}],"author":[{"embeddable":true,"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/users\/1"}],"version-history":[{"count":9,"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article\/2127\/revisions"}],"predecessor-version":[{"id":3123,"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article\/2127\/revisions\/3123"}],"wp:attachment":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/media?parent=2127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}