This is the solution for attributes contains spaces.
I use this hook https://academy.bricksbuilder.io/article/filter-bricks-element-render_attributes/
I need set html attribute: SRCSET.
This attribute contain list of URL’s separated with comma and space.
Spaces are replaced to %20
.
This is done into file wp-content/themes/bricks/includes/elements/base.php line 1870 by function esc_url()
.
Solution for example SRCSET tag:
/**
* Add SRCSET for image gallery .gallery-grid-square-col-5
* @link https://academy.bricksbuilder.io/article/filter-bricks-element-render_attributes/
*/
add_filter( 'bricks/element/render_attributes', function ( $attributes, $key, $element ) {
if ( $element->id == 'njrsgc' && str_starts_with( $key, 'img-' ) ) {
$item = str_replace( 'img-', 'item-', $key );
$item_id = $element->attributes[ $item ][ 'data-id' ][0];
$attributes[ $key ][ 'srcset' ] = wp_get_attachment_image_srcset( $item_id, 'full' );
}
return $attributes;
}, 10, 3 );
/**
* Filter Modification: bricks/element/render_attributes
* If attribute value contains space
* First, space is replaced into file wp-content/themes/bricks/includes/elements/base.php
* This code reverse this replace
* Replace %20 to space
* @link https://academy.bricksbuilder.io/article/filter-bricks-element-render_attributes/
*/
function fnc_clean_url( $good_protocol_url, $original_url, $_context ) {
if ( str_contains( $good_protocol_url, 'w,%20https://') ) {
$good_protocol_url = str_replace( '%20', ' ', $good_protocol_url );
}
return $good_protocol_url;
}
add_filter( 'clean_url', 'fnc_clean_url', 10, 3 );