Meow Apps

Gallery Custom Links

Gallery Custom Links allows you to link images from galleries to a specified URL. Tested with WordPress Gallery, Gutenberg, the Meow Gallery, and others. You can download it for free on the WordPress Repository.

Usage

Two fields are added to your images, in your Media Library: Link URL and Link Target. If at least, the Link URL is set up, this image will link to that URL every time it is used within a gallery. Lightbox will be automatically disabled for those images.

The .custom-link and .no-lightbox classes will be added to the A-Link. That way, you can style the new link the way you would like it. For example, it is recommended to use the following CSS to make sure the image behaves like a link when there is a mouse hover.

​.custom-link {
     cursor: pointer !important;
 }

Compatibility

It currently works with the native WP Gallery, the Gutenberg Gallery, and the Meow Gallery. It should actually work with any gallery plugin using the ‘gallery’ class and Responsive Images (src-set). Let me know if you would like more galleries to be supported, it should be easy.

Filters

There are filters available, through them, you can customize the behavior of the plugin. You can implement those filters by adding code in your functions.php or by using the Code Snippet plugin.

Decide if it is active or not

Through the gallery_custom_links_enabled filter, you can decide if Gallery Custom Links should be enabled or not. Usually, you would like to do this depending on the post/page. For example, the following code will only enable the plugin if the page being loaded has the ID 123.

add_filter( 'gallery_custom_links_enabled', 'my_gallery_custom_links_enabled', 25, 1 );

function my_gallery_custom_links_enabled( $isEnabled ) {
	$id = get_the_ID();
	if ( $id === 1773 )
		return true;
	return false;
}

If the code above is not working, make sure the ID is actually retrieved. Depending on the page or post, the get_the_id might be not the right function to call.

Analyze images in more CSS classes

By default, the plugin will look for images located in .gallery and .wp-block-gallery. If the Meow Gallery or the Kadence Gallery is installed, the plugin will also work. However, if it is not taking care of your images, you will need to define more CSS classes to parse. You can use this code to do so.

add_filter( 'gallery_custom_links_classes', 'my_gallery_custom_links_classes', 10, 1 );

function my_gallery_custom_links_classes( $classes ) {
	array_push( $classes, '.my-gallery' );
	return $classes;
}