diff --git a/assets/scss/components/main/_gutenberg.scss b/assets/scss/components/main/_gutenberg.scss index d660ecb2d1..585efdb986 100644 --- a/assets/scss/components/main/_gutenberg.scss +++ b/assets/scss/components/main/_gutenberg.scss @@ -150,4 +150,3 @@ blockquote { margin-right: calc(50% - 35vw); } } - diff --git a/inc/views/template_parts.php b/inc/views/template_parts.php index 1bffef416e..f33b879482 100644 --- a/inc/views/template_parts.php +++ b/inc/views/template_parts.php @@ -36,6 +36,7 @@ class Template_Parts extends Base_View { public function init() { add_action( 'wp_enqueue_scripts', array( $this, 'add_featured_post_style' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'add_vertical_spacing_style' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'add_lightbox_style' ) ); add_action( 'neve_do_featured_post', array( $this, 'render_featured_post' ) ); add_action( 'neve_blog_post_template_part_content', array( $this, 'render_post' ) ); add_filter( 'excerpt_more', array( $this, 'link_excerpt_more' ) ); @@ -552,4 +553,33 @@ public function get_ordered_components( $associative = false ) { return json_decode( get_theme_mod( 'neve_post_content_ordering', wp_json_encode( $default_ordered_components ) ), $associative ); } + + /** + * Add inline lightbox style if the post content includes an image block with lightbox. + */ + public function add_lightbox_style() { + global $post; + if ( ! has_block( 'core/image', $post ) ) { + return; + } + $blocks = parse_blocks( $post->post_content ); + $blocks = array_filter( + $blocks, + function( $block ) { + return 'core/image' === $block['blockName'] && ! empty( $block['attrs']['lightbox']['enabled'] ); + } + ); + if ( empty( $blocks ) ) { + return; + } + $inline_style = ' + .wp-lightbox-overlay figure img { + height: var(--wp--lightbox-image-height); + min-height: var(--wp--lightbox-image-height); + min-width: var(--wp--lightbox-image-width); + width: var(--wp--lightbox-image-width); + } + '; + wp_add_inline_style( 'neve-style', Dynamic_Css::minify_css( $inline_style ) ); + } }