Lightbox for Gallery & Image Block

説明

この WordPress プラグインは、WordPress 標準の「ギャラリー」ブロック &「画像」ブロックに、シンプル & 軽量なライトボックスを追加します。投稿に「ギャラリー」ブロックや「画像」ブロックが含まれているかどうかを検出し、依存関係のない純粋なJavaScriptライトボックススクリプトで、モダンなミニマムルックの、baguetteBox.js をロードして初期化します。

ロックイン効果はありません。新しいブロックエディター/ Gutenberg ブロックを追加せず、WordPress 標準の「ギャラリー」ブロックと「画像」ブロックにのみ依存しています。このプラグインはいつでも無効化でき、「ギャラリー」ブロックと「画像」ブロックは、これまで通り動作します。ライトボックスがないだけです。

ただし、覚えておくべき重要なことが一つ: 「画像」ブロック & 「ギャラリー」ブロックを正しく動作させるには、必ず リンク 画像ファイルにリンク または メディアファイルに画像をリンク (以下のスクリーンショットを参照) を選択する必要があります。なし または 添付ページにリンク を選択した場合は、機能しません。しかし、特定の画像やギャラリーのライトボックスが不要な場合は、それでもかまいません。

Jakson の YouTube 動画にアクセスし、このプラグインのレビューをご覧ください:

Features

以下は baguetteBox.js の特徴です:

  • 純粋な JavaScript で記述
  • 依存関係 (例: jQuery) なし
  • 画像キャプション対応
  • レスポンシブ
  • スワイプ・ジェスチャー対応
  • 約 13 KB、gzip 圧縮で 7KB

Works with

  • 「ギャラリー」ブロック (デフォルトのブロック)
  • 「画像」ブロック (デフォルトのブロック)
  • 「メディアとテキスト」ブロック (デフォルトのブロック)
  • ギャラリー (デフォルトのクラシック・エディター・ギャラリー)
  • コ・ブロック・ギャラリー・コラージュ / メイソンリー (石積み) / オフセット / 縦積み
  • Meow ギャラリー (+ 「ギャラリー」ブロック)

ギャラリー & 画像が正しく動作するように、忘れずにリンク先 メディアファイル を選択してください。

注意: 現時点では、投稿内のブロックのみが対応しています。ウィジェット内のブロックには対応していません。動作させることはできますが、必要なスタイルとスクリプトを自分でキューに入れる必要があります。FAQ –> 投稿の外にあるブロックや、デフォルトでサポートされていないブロックタイプに必要なアセット (スクリプトとスタイル) をキューに入れるには ?を参照してください。

スクリーンショット

  • 「ギャラリー」ブロック用のシンプル、モダン、ミニマルなライトボックス
  • 「画像」ブロックの 画像ファイルへのリンクリンク を設定する
  • 「ギャラリー」ブロックの メディアファイルに画像をリンクリンク を設定する

インストール

  1. gallery-block-lightbox フォルダーを /wp-content/plugins/ ディレクトリにアップロードします。
  2. WordPress の「プラグイン」メニューからプラグインを有効化します
  3. 投稿に「ギャラリー」ブロックまたは「画像」ブロックを追加し、リンク先 メディアファイル をセットします
  4. フロントエンドで画像をクリックして、Lightbox の付いたギャラリーや画像をチェックしてください

FAQ

When I click on an image, nothing happens

Check if you used the built in Gallery Block and if Link to is set to Media File in the Block sidebar. On an Image Block choose Add Link at the Toolbar.

Does it work for single images?

Yes! Just set the Link at the Toolbar to Media File

Can I deactivate the Lightbox for a single Image or Gallery?

Set Media File to None or remove the Link.

Is there a way to set the default Link to option to Media File?

Since WordPress 5.6 you can now set the default behavior for Link to. Go to yourblog.com/wp-admin/options.php and search for image_default_link_type. Set the value to file and hit save. This will apply to all new Image & Gallery Blocks.

Or you can add the follow snipped (WordPress 5.7+ / PHP 7.4+) to your functions.php:
add_filter( 'option_image_default_link_type', fn () => 'file' );

How can I add my own Block? / Can I change the CSS selector?

You can change the CSS selector to a gallery (or galleries) containing <a> tags used by baguetteBox.js with the baguettebox_selector filter:
add_filter( 'baguettebox_selector', function( $selector ) { return $selector . ',.my-gallery'; } )
You can override the full selector by just returing your selector e.g. to show all images in your post in one lightbox (not per Gallery/Image Block):
add_filter( 'baguettebox_selector', function() { return '.entry-content'; } )

How to enqueue the necessary assets (script & style) for blocks outside of posts or for block types that are not supported by default?

If you use a Gallery or Image Block outside a post e.g. inside a Widget and want to apply the Lightbox, you need to ensure that the required baguettebox assets (script & style) are queued using the baguettebox_enqueue_assets filter.

If the Widget is on every page or the majority of pages, you can just enqueue the baguettebox assets everywhere. Just add the following snippet to functions.php:
add_filter( 'baguettebox_enqueue_assets', '__return_true' );
If your Widget is just at the front page, use is_front_page():
add_filter( 'baguettebox_enqueue_assets', function( $enqueue_assets ) { return is_front_page(); } );
If you want to use the Gallery & Image Block Lightbox plugin with a block type that is not supported by default, you can make use of the has_block() function. For instance, in the case of the Kadence Blocks Advanced Gallery, use:
add_filter( 'baguettebox_enqueue_assets', function ( $enqueue_assets ) {
return $enqueue_assets || has_block( 'kadence/advancedgallery' );
} );

Of course, in the previous example you also have to add the appropriate baguettebox selector, i.e.
add_filter( 'baguettebox_selector', function( $selector ) {
return $selector . ',.wp-block-kadence-advancedgallery';
} );

Can I change or disable the animation on image transitions?

By default, baguetteBox.js shows a slide-in animation on image transitions. You can change it to the following filter to 'fadeIn':
add_filter( 'baguettebox_animation', function () { return 'fadeIn'; } );
Or disable the animation completely with 'false':
add_filter( 'baguettebox_animation', function () { return 'false'; } );

Can I exclude single images from applying the lightbox?

You can remove the link from the image or add the CSS class no-lightbox to the image link. Not to the image directly; you have to add the class to the link.

評価

2025年9月19日
Як же довго шукав такий плагін. Оцінка 5. Плагін робочий і без зайвого барахла (реклама, про версія). Дуже дякую!
2025年8月21日
Thanks for your great work. Good plugin, exactly what i was looking for. It follows the KISS principle. Keep It Simple, Stupid!
2025年8月2日
I tested more than five plugins, and this is the first free one that’s exactly how I would have programmed it. Thank you so much!
2025年4月15日
Lightweight, not tons of settings, responsive, you can zoom in on mobiles, nice style, works with native Guthenberg blocks, simple tutorial. That’s perfect. Thank you a lot for all your efforts to maintain this project. It’s really appreciated!
2025年3月21日 1 reply
My favourite lightweight lightbox viewer closed recently and I needed something to replace it. This plugin is super lightweight, and has exactly the same admin interface, i.e. nothing to do, just install it and watch the magic happen on existing images and galleries. What’s not to like.
87件のレビューをすべて表示

貢献者と開発者

Lightbox for Gallery & Image Block はオープンソースソフトウェアです。以下の人々がこのプラグインに貢献しています。

貢献者

“Lightbox for Gallery & Image Block” は9ロケールに翻訳されています。 翻訳者のみなさん、翻訳へのご協力ありがとうございます。

“Lightbox for Gallery & Image Block” をあなたの言語に翻訳しましょう。

開発に興味がありますか ?

コードを閲覧するか、SVN リポジトリをチェックするか、開発ログRSS で購読してみてください。

変更履歴

1.16

  • Add filter baguettebox_animation to choose between ‘slideIn’ | ‘fadeIn’ | ‘false’ animation styles on image transitions.

1.15

  • Add filter baguettebox_captions to change the JavaScript function to get the caption of an image

1.14

1.13

  • Support GenerateBlocks Image

1.12

  • Support Meow Gallery (+ Gallery Block)

1.11

  • Add filter baguettebox_enqueue_assets to control enqueing of baguettebox assets.

1.10.1

  • Fix Image in Media & Text Block

1.10.0

  • Add two Filter baguettebox_selector for the baguetteBox.js CSS selector and baguettebox_filter for the baguetteBox.js file type RegExp filter

1.9.0

  • Support new Gallery Block format (will be released with WordPress 5.9 in December 2021) https://make.wordpress.org/core/2021/08/20/gallery-block-refactor-dev-note/

1.8.5

  • Fix Caption for the single Image Block

1.8.4

  • Add Caption Support for the Classic Editor Gallery

1.8.3

  • Fix Regex Filter

1.8.2

  • Add support for file links with query parameter at the end

1.8.1

  • Fix image link filter

1.8.0

  • Add support for .avif, .heif/.heic, .tif

1.7.0

  • Add support for Media and Text Block

1.6.0

  • Add support for CoBlocks Gallery Collage / Masonry / Offset / Stacked

1.5.0

  • Add support for Classic Editor Gallery

1.4.0

  • Add support for .svg images

1.3.1

  • Remove trailing slash from register_script/style

1.3.0

  • Support for the default Image Block

1.2.0

  • Support HTML for the Caption

1.0.0

First release