We have a normal WordPress gallery on a development webpage.

enter image description here

The page is custom content through Advanced Custom Fields, and we are wrapping the section above's content like so:

  $content = get_sub_field('wysiwyg');
  if ( function_exists('slb_activate') ) {
    $content = slb_activate($content);
  echo $content;

The lightbox functionality is generated by Simple Lightbox, and slb_activate is a function of this plugin, which adds the lightbox functionality to any gallery in the ACF content.

The designer wants the last image in the gallery (the purple one) to link to a different WordPress page while maintaining the lightbox functionality for the rest of the gallery.

I don't know if we need a WordPress filter (which to me would be complicated by the slb_activate function, or some jQuery, and target .gallery-item:last-of-type, replacing the URL with a new one?

If so, we'd like to take the page slug (bathrooms) from https://herodevelopment.com.au/allbathroomgear/design-build/bathrooms/ and use this slug to generate a new URL of https://herodevelopment.com.au/allbathroomgear/album/bathrooms/

(so going from /design-build/bathrooms/ to /album/bathrooms/ on the final production website).

I'd appreciate any help, as I am unfortunately not a developer.


2 Answers 2


By javascript, You should replace the link on the last item with new one and change tag's attribute, data-slb-active, to "0". Please use the following javascript.

jQuery("#gallery-1 .gallery-item:last-of-type a").attr("href", "https://herodevelopment.com.au/allbathroomgear/album/bathrooms/").attr("data-slb-active", "0");

  • Thanks very much Andre. You might want to wrap your comments in backticks to format it. Cheers.
    – SRDMH
    Feb 23, 2021 at 4:20

Replace your code with the following:

$content = get_sub_field( 'wysiwyg' );
if ( function_exists( 'slb_activate' ) ) {
    $url_request = isset( $_SERVER['REQUEST_URI'] ) ?
        filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_STRING ) :
    $url_path    = wp_parse_url( $url_request, PHP_URL_PATH );
    $url_path    = preg_replace( '#/.+/(.+)/#', '/album/$1/', $url_path );
    $content     = str_replace( '/wp-content/uploads/2021/02/gallery-thumb.jpg', $url_path, $content );
    $content     = slb_activate( $content );
echo $content;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.