Very late to the party but I found a fix. (Actually two). Both require adding PHP code into either bricks or a snippet plugin.
Note: Optimisation/caching plugins may try and override image management so make sure to check out any image optimisation / lazy loading setting you have.
Option 1.
The first is to add a block of PHP that automates the detection of a looping item such as a slideshow and adds the loading and fetchpriority attributes automatically.
// Automatically detects looping and sets appropritate fetchpriority and loading parameters
add_filter( 'wp_get_attachment_image_attributes', function ( $attr ) {
// Only target the hero slider image
if ( empty( $attr['class'] ) || strpos( $attr['class'], 'brxe-scgqtv' ) === false ) {
return $attr;
}
if ( ! class_exists( '\Bricks\Query' ) || ! \Bricks\Query::is_any_looping() ) {
return $attr;
}
if ( \Bricks\Query::get_loop_index() === 0 ) {
$attr['loading'] = 'eager';
$attr['fetchpriority'] = 'high';
$attr['decoding'] = 'sync';
} else {
$attr['loading'] = 'lazy';
$attr['decoding'] = 'async';
unset( $attr['fetchpriority'] );
}
return $attr;
}, 999 );
Option 2.
The second option allows for greater flexibility in defining where you want to use these parameters. To use, Add the PHP code below.
// Force nestable sliders to only load the first images as eager.
function mm_slide_loading() {
return \Bricks\Query::get_loop_index() === 0 ? 'eager' : 'lazy';
}
function mm_slide_priority() {
return \Bricks\Query::get_loop_index() === 0 ? 'high' : 'auto';
}
// Bricks 1.9.7+ requires echo functions to be whitelisted
add_filter( 'bricks/code/echo_function_names', function () {
return [ 'mm_slide_loading', 'mm_slide_priority' ];
} );
The first function takes care of the ‘loading’ parameter by outputting a word ‘eager’ or ‘lazy’ depending on whether it is the first looping item.
The second function takes care of the ‘fetchpriority’ parameter by outputting high or auto depending on whether it is the first slide.
The last add_filter is for Bricks to approve these two functions to run. If you already have this function from other PHP, add the ‘mm_slide_loading’, ‘mm_slide_priority’ to the list of functions already there.
To use these, click on the image and then go to the Attributes section.
Add two attributes.
Name: loading
Value: {echo:mm_slide_loading}
Name: fetchpriority
Value: {echo:mm_slide_priority}
That’s it. Good luck.
(Bricks, if you are reading, please add this to automatically be managed. It’s crazy that we have to go to this extent).