Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lightbox functionality to Post Featured Image block #69279

Open
freetanga opened this issue Feb 22, 2025 · 0 comments
Open

Add lightbox functionality to Post Featured Image block #69279

freetanga opened this issue Feb 22, 2025 · 0 comments
Labels
[Block] Post Featured Image Affects the Post Featured Image Block [Type] Enhancement A suggestion for improvement.

Comments

@freetanga
Copy link

Overview

The Image block in Gutenberg includes a native lightbox functionality that allows users to expand images in a modal view. However, this functionality is not available in the Post Featured Image block, even though it would be equally useful in this context.

Current Behavior

  • Image block: Has a lightbox option that can be enabled through block settings
  • Post Featured Image block: No lightbox functionality available
  • Users need to implement workarounds or custom solutions to achieve this functionality

Proposed Enhancement

Add the same lightbox functionality that exists in the Image block to the Post Featured Image block. This would:

  • Maintain consistency across image-handling blocks
  • Improve user experience when viewing featured images
  • Eliminate the need for custom solutions or additional plugins

Use Case

When users view a single post, they often want to see the featured image in more detail. Currently, they have two less-than-ideal options:

  1. Link the featured image to the media file (which takes users away from the post)
  2. Leave the image without any interaction capability

Having lightbox functionality would solve this by allowing users to:

  • View the full-size image without leaving the post
  • Close the lightbox and continue reading seamlessly
  • Have a consistent experience with other images in the post

Technical Details

The Image block already implements this functionality through:

  • Lightbox attribute in block.json
  • Interactive state handling
  • Modal view implementation

The same implementation could be extended to the Post Featured Image block with minimal modifications, as both blocks handle similar content types.

Example Implementation

I've successfully implemented this functionality as a custom solution. Here's the approach used:

// Converting featured image to use Image block's lightbox
$block = [
    'blockName' => 'core/image',
    'attrs' => [
        'id' => $post_thumbnail_id,
        'sizeSlug' => 'large',
        'linkDestination' => 'none',
        'className' => 'wp-block-post-featured-image',
        'lightbox' => [
            'enabled' => true
        ]
    ],
    'innerHTML' => sprintf(
        '<figure class="wp-block-image size-large wp-lightbox-container">%s</figure>',
        $html
    )
];
@freetanga freetanga added the [Type] Enhancement A suggestion for improvement. label Feb 22, 2025
@t-hamano t-hamano added the [Block] Post Featured Image Affects the Post Featured Image Block label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Featured Image Affects the Post Featured Image Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants