Problem:
The user is using a lazy loading plugin to optimize the loading of images, he needs to add a specific class to the tag generated by the Image block.
The classes added to the image block settings are added in the
Solution:
We can work around this using custom code:
function add_class_to_image_block( $block_content, $block ) { if ( $block['blockName'] === 'toolset-blocks/image' ) { return str_replace( '<img src', '<img class="my-class" src', $block_content ); } return $block_content; } add_filter( 'render_block', 'add_class_to_image_block', 10, 2 );
Relevant Documentation:
https://developer.wordpress.org/reference/hooks/render_block/
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9:00 – 13:00 |
14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - | - | 14:00 – 18:00 |
Supporter timezone: Africa/Casablanca (GMT+01:00)
This topic contains 5 replies, has 2 voices.
Last updated by 3 years, 11 months ago.
Assisted by: Jamal.