Make every Image block open in a full-screen lightbox when clicked, using WordPress's built-in "Expand on click" feature.
add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) {
return $theme_json->update_with( [
'version' => 3,
'settings' => [
'blocks' => [
'core/image' => [
'lightbox' => [
'enabled' => true,
'allowEditing' => true,
],
],
],
],
] );
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Since WordPress 6.4, the Image block has an “Expand on click” option that opens a lightbox with no plugin. It’s off by default and has to be turned on one image at a time. This snippet makes it the default for every image.
Block settings come from theme.json. The wp_theme_json_data_theme filter changes them from PHP, here setting the Image block’s lightbox.enabled to true, so every image opens in a lightbox unless an editor turns it off.
allowEditing keeps the option in the block toolbar so editors can switch it off for individual images.
View a post with an Image block and click the image. It should open full screen.