Spectra Image Gallery block – need to keep the layout as TILED
-
This single image has been added by a Spectra Image gallery – in this case with just a single image. I select Tiled layout and save it – it displays as you can see correctly on the above link. However, when i open the page to edit some content, the image gallery keeps reverting to a grid layout, as it must look and see there are less than 4 images, so the image wouls show massive taking up most of the page. If i rememeber to check the image as Tiled, before i save my changes – all is well. However, this is a real pain and i often forget, then have to popen and edit and check it as tiled again, then save again. I have looked at some modifications in the Additional CSS to try and make it stay as tiled. I even asked ChatGPT, which suggested some <php>snippet code to run on pages, to try and make it change/render as Tiled layout – see code below. This did not work sadly. Do you have any answers? Can I set the tiled layout to stay as it should, no matter how many images are in the gallery block 5,4,3,2, or even just the 1 ? Thanks. Richard.
// Modify Spectra Image Gallery block to enforce tiled mode during rendering
add_filter(‘render_block’, ‘force_tile_mode_on_render_specific’, 10, 2);function force_tile_mode_on_render_specific($block_content, $block) {
// Check if the block is a Spectra image gallery block
if (isset($block[‘blockName’]) && $block[‘blockName’] === ‘uagb/image-gallery’) {
// Force the feedLayout attribute to be “tiled”
if (isset($block[‘attrs’]) && isset($block[‘attrs’][‘feedLayout’])) {
$block[‘attrs’][‘feedLayout’] = ’tiled’; // Enforce tiled layout
}// Ensure that the block has the correct class or ID if (strpos($block_content, 'uagb-block-7a613e15') !== false || strpos($block_content, 'wp-block-uagb-image-gallery') !== false) { // Re-render the block with the modified attributes $block_content = render_block($block); } } return $block_content;
}
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.