After HOURS of research, this is my complete wordpress fancybox handling.
add_action('wp_head', 'fancybox_init');
function fancybox_init() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var select = $('a[href$=".bmp"],a[href$=".gif"],a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".BMP"],a[href$=".GIF"],a[href$=".JPG"],a[href$=".JPEG"],a[href$=".PNG"]'); // select image files
select.attr('data-fancybox-group', 'gallery');
select.attr('class', 'fancybox');
select.fancybox();
///////////make 'go' button and go to this page //////////
$.fancybox.defaults.btnTpl.go = '<button data-fancybox-go class="fancybox-button fancybox-button--go" title="go to this page">'+"go"+'</button>';
$('body').on('click', '[data-fancybox-go]', function() {
var linx=$.fancybox.getInstance().current.opts.$orig.data('item');
window.location.href = linx;
});
//////////////////// init fancybox //////////
$(".fancybox").fancybox({
beforeShow: function () {
this.title = $(this.element).find("img").attr("alt"); },
thumbs : {autoStart : true, axis : 'x'},
loop : true,
padding :0,
buttons: ["go", "zoom", "share", "slideShow", "fullScreen", "download", "thumbs", "close" ],
margin : 20,
wrapCSS : '',
openEffect : 'elastic',
openSpeed : 650,
arrows : true,
closeEffect : 'elastic',
closeSpeed : 650,
closeBtn : true,
closeClick : false,
nextClick : false,
prevEffect : 'elastic',
prevSpeed : 650,
nextEffect : 'elastic',
nextSpeed : 650,
pixelRatio: 1, // Set to 2 for retina display support
autoSize : true,
autoHeight : false,
autoWidth : false,
autoResize : true,
fitToView : true,
aspectRatio : false,
topRatio : 0.5,
leftRatio : 0.5,
scrolling : 'auto', // 'auto', 'yes' or 'no'
mouseWheel : true,
autoPlay : false,
playSpeed : 3000,
preload : 3,
modal : false,
helpers : {
title : {
type : 'inside', // outside
}
}
});
//////////////////////
$(".fancybox-media")
.fancybox({
openEffect : 'none',
closeEffect : 'none',
prevEffect : 'none',
nextEffect : 'none',
arrows : false,
helpers : {
media : {},
buttons : {}
}
});
//////////////////////
});
I passed the link I want to redirect to, here using data-item:
<a href="https://mywebsite.com/img1.jpg" data-fancybox="gallery" data-item="https://whereIwantToGo.com" class="img-fluid" data-caption="image caption"><img src="https://mywebsite.com/img1.jpg" alt=""></a>
-
This reply was modified 3 years ago by Stathi.
-
This reply was modified 3 years ago by Stathi.