本文档介绍了 WordPress 6.4 中引入的 Lightbox 设置,该设置专用于核心 Image 块,允许启用点击展开图像的灯箱功能。文档详细说明了如何在 theme.json 中配置相关属性,以全局启用或禁用此功能,并控制用户编辑权限。
{
"version": 2,
"settings": {
"blocks": {
"core/image": {
"lightbox": {
"enabled": true
}
}
}
}
}{
"version": 2,
"settings": {
"blocks": {
"core/image": {
"lightbox": {
"allowEditing": false
}
}
}
}
} settings.lightbox is a specific setting that you can enable for supported blocks. It enables a lightbox feature that expands an image when a site visitor clicks on an image.
This setting is only available as of WordPress 6.4 and is specific to the core Image block (core/image).
The lightbox setting is specific to the Image block, so the following examples will be shown in that context.
The lightbox property is an object that has two nested properties that you can configure:
enabled: Whether to enable the lightbox feature for the Image block. The default value is undefined (the equivalent of being disabled).allowEditing: Whether to show the Expand on click option in the interface, which allows the user to enable/disable lightbox for individual images. Defaults to true.Here is a look at the default theme.json:
{
"version": 2,
"settings": {
"blocks": {
"core/image": {
"lightbox": {
"allowEditing": true
}
}
}
}
}
To enable the lightbox feature for Image blocks used throughout the site, you must set settings.blocks.core/image.lightbox.enabled to true in theme.json:
{
"version": 2,
"settings": {
"blocks": {
"core/image": {
"lightbox": {
"enabled": true
}
}
}
}
}
On the front-end of the site, visitors will be able to expand the image when clicking on it. The image will then overlay the entire screen (including an x button for closing the overlay), as shown below:

By default, WordPress will show an Expand on Click option under the Settings tab for the Image block:

This control allows your theme’s users to enable or disable the lightbox feature on a per-block basis.
To disallow user editing, you must set settings.blocks.core/image.lightbox.allowEditing to false in theme.json:
{
"version": 2,
"settings": {
"blocks": {
"core/image": {
"lightbox": {
"allowEditing": false
}
}
}
}
}