Last active
May 30, 2025 15:08
-
-
Save addisonhall/bffaad2db733e709f2ed7204ca6364af to your computer and use it in GitHub Desktop.
"Lightbox for Gallery & Image Block" customizations for ACF/GenerateBlocks setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* I'm using this with my GeneratePress child theme. Add to functions.php. | |
* @see https://youtu.be/xQMCRfICp7E | |
*/ | |
/** | |
* Enqueue simple lightbox assets by default | |
* @link https://wordpress.org/plugins/gallery-block-lightbox/ | |
*/ | |
add_filter( 'baguettebox_enqueue_assets', '__return_true' ); | |
/** | |
* Filter for custom captions on gallery-block-lightbox.php | |
* @link https://github.com/goaround/gallery-block-lightbox/blob/c4c72f1b86c82f9f8e6c1f0cdd5e94e2331ed0a1/gallery-block-lightbox.php#L50 | |
*/ | |
add_filter( 'baguettebox_captions', 'gpc_baguettebox_captions' ); | |
function gpc_baguettebox_captions() { | |
// the "t" in t.parentElement.classList.contains('your-custom-class') targets the <a> element of your gallery image | |
$custom_selector = 't.parentElement.classList.contains("gpc-gallery-media-item")'; | |
return 'function(t){var e=t.parentElement.classList.contains("wp-block-image")||t.parentElement.classList.contains("wp-block-media-text__media")||' . $custom_selector . '?t.parentElement.querySelector("figcaption"):t.parentElement.parentElement.querySelector("figcaption,dd");return!!e&&e.innerHTML}'; | |
} | |
/** | |
* Add custom HTML tag(s) to GenerateBlocks Loop Item | |
* @link https://generate.support/topic/gb-headline-dynamic-data-open-in-new-tab-not-workin/#post-165999 | |
*/ | |
add_filter('block_type_metadata', function($metadata) { | |
if (isset($metadata['name']) && $metadata['name'] === 'generateblocks/loop-item') { | |
$metadata['attributes']['tagName']['enum'] = array_merge( | |
$metadata['attributes']['tagName']['enum'], | |
// include array of tag/element names, for example: ['figure', 'dd', 'aside'] | |
['figure'] | |
); | |
} | |
return $metadata; | |
}, 10, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment