This requires adding some custom code in your theme's functions.php file, as well as, writing some custom JavaScript. Let me explain this in some steps below.
1) I am going to use a 3rd party lightbox plugin, called Fancybox (hidden link). Download from the Fancybox site and upload somewhere in your theme's folder (after unzip). You will apparently need following files:
- jquery.fancybox-1.3.4.pack.js
- jquery.fancybox-1.3.4.css
It's good to upload all content from 'source' folder in 'fancybox' folder under your theme's folder. So you can easily follow the example how-to as mentioned at hidden link (if needed later on).
2) Open functions.php file in a text editor and add following code at the end of file:
function load_custom_wp_admin_scripts() {
wp_register_style( 'fancybox-css', get_template_directory_uri() . '/fancybox/jquery.fancybox.css', false, '1.0.0' );
wp_register_style( 'mycustom-css', get_template_directory_uri() . '/fancybox/my-custom.css', false, '1.0.0' );
wp_enqueue_style( 'fancybox-css' );
wp_enqueue_style( 'mycustom-css' );
wp_enqueue_script( 'fancybox-js', get_template_directory_uri() . '/fancybox/jquery.fancybox.pack.js' );
wp_enqueue_script( 'mycustom-js', get_template_directory_uri() . '/fancybox/my-custom.js' );
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_scripts' );
Please notice my-custom.css and my-custom.js in above code, you will create and add code to these files in later steps. At this point save functions.php file.
3) Create a new file 'my-custom.js' in same fancybox folder with following content:
jQuery(document).ready(function($){
$(".wpt-file-preview img.attachment-thumbnail").on("click", function(e){
var img = $(this).parent().parent().find("input[type=text]").val();
//console.log(img);
$(".wpt-file-preview img.attachment-thumbnail").fancybox({
'href': img
});
});
});
This will enable the Fancybox on image thumbnails, while considering the URL in that field as a preview image (large image, uploaded by user).
4) Create a new file 'my-custom.css' to add some work around on these images, with following content:
.wpt-file-preview img.attachment-thumbnail {
display: block!important;
cursor: pointer!important;
}
By default when you click on an image using Fancybox, it will hide the original thumbnail. Also the image isn't an A tag, so it can visually confuse if it is clickable or not. Above CSS resolves both issues.
I created this code on my localhost and tested it thoroughly. I hope if you follow these steps carefully, you can achieve the same.
Please let me know if I can help you with anything related.