Turn On the Image Lightbox by Default
Switches on the built-in "Enlarge on click" lightbox for every Image block, so readers can view photos full screen without a lightbox plugin.
Opens WPIDE on
Code
add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) {
return $theme_json->update_with( array(
'version' => 3,
'settings' => array(
'blocks' => array(
'core/image' => array(
'lightbox' => array(
'enabled' => true,
'allowEditing' => true,
),
),
),
),
) );
} );
Notes
Images linked to a page or file keep their link instead of the lightbox. Editors can still turn it off per image.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.