# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: lightbox, images, blocks
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/image-lightbox-by-default/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Turn On the Image Lightbox by Default" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
