Update: I’ve somehow conquered the PHP demon, and gotten a solution to this (though I cannot guarantee it’s the best solution as I’m inexperienced). Basically, Lightbox plugins don’t work with onclick. They require a normal link, so I needed to find a way to do that.
I’m not sure how to share the code I’ve done, and I’m not entirely sure it’s the best solution to begin with, but it works for me. So, I’ll try to share what I’ve done below.
Functionality/Instructions:
-A new checkbox added in gallery item settings called “Open Image”. This can be done in inc/builder/sections/gallery/definition.php by finding all instances of open-new-tab and duplicating the code/changing to open-image.
-When checked, the get_gallery_item_onclick function will return blank (any link in the link box will be ignored). This can be done in inc/builder/sections/section-front-end-helpers.php in the ttfmake_builder_get_gallery_item_onclick function by adding:
if (isset( $item['open-image'] ) && $item['open-image'] === 1) {
return '';
}
Make sure this is below where $item is set.
Then, you’ll want to add a new function just below that function to pull the image URL:
function ttfmake_builder_get_gallery_item_imagelink( $ttfmake_section_data, $i ) {
if ( ! ttfmake_builder_is_section_type( 'gallery', $ttfmake_section_data ) ) {
return '';
}
$item = $ttfmake_section_data['gallery-items'][$i - 1];
$image_src = ttfmake_get_image_src( $item[ 'image-id' ], 'large' );
$url = esc_url_raw( $image_src[0] );
return $url;
}
-When checked, a normal link will be added around the builder-gallery-content div, which pulls the item’s image URL. This can be done in inc/builder/sections/gallery/frontend-template.php right above the builder-gallery-content div.
<?php if (isset( $item['open-image'] ) && $item['open-image'] === 1) : ?>
<a href="<?php echo ttfmake_builder_get_gallery_item_imagelink( $ttfmake_section_data, $i ); ?>">
<?php endif; ?>
And another to close out the a tag, right below the closing tag for builder-gallery-content:
<?php if (isset( $item['open-image'] ) && $item['open-image'] === 1) : ?>
</a>
<?php endif; ?>
-Because it is a normal image link, lightbox plugins should pick it up.
-
This reply was modified 7 years, 7 months ago by moosecat.
-
This reply was modified 7 years, 7 months ago by moosecat.