0

I'm having one problem that i can't solve for quite some time. I'm building a portfolio site using Expositio theme. I need all pictures to open in lightbox when clicked, but instead of that, when I click on image it takes me to media file in new tab. I can see lightbox working for one second and then it jumps on link of the uplaoded image (http://localhost/wordpress/wp-content/uploads/2017/05/otherwork1d.jpg)

I need to disable so the lightbox would be visible. If anyone could help I would be most grateful.

Dule.

  • Did you add the lightbox to the theme? Did you add it on javascript or did you install a plugin for that? If it was on javascript can you add here the code you've used? – dbeja Jul 8 '17 at 21:29
  • I just installed easy fancybox plugin, I didn't add any code.. – dajza bata Jul 9 '17 at 17:26
  • It could be some plugin conflict. Do you have any error on console? Do you have any live link? Try to disable all plugins and see if you still have the same problem. Or try to change the theme and see if still doesn't work. – dbeja Jul 9 '17 at 22:07
  • @dbeja. No, no errors, i don't have live links, i tried to disable plugins but that didn't help, but when i changed theme to another one, easy fancybox works perfectly, so it must be the expositio theme that makes this happen. – dajza bata Jul 10 '17 at 11:19
  • @dbeja I forgot, i bumped into wp gallery custom links plugin that gives me option to set images to open in same window, but that also didn't work, expositio theme is causing this for sure.. Can You tell me where to look, and where could be the part of code that links images and opens them on uploads skipping the lightbox effect? I know a bit of html and css, but I don't know any javascript. I looked in functions.js and functions.php files but I was unable to fix the problem – dajza bata Jul 10 '17 at 11:30
0

So, the problem is that on Expositio theme they are adding some jQuery code to all links, that if you're not closing the mobile menu, after a configurable number of seconds (1 second by default) just redirect site to the link url.

If you go to line 260 of js/functions.js you find this:

$('a').on('click', function(e) {
    e.preventDefault();
    var _this = $(this);
    // close mobile menu if it's open, redirect otherwise
    if (_body.hasClass('toggled-on') && _this.parents('#page').length == 1
        && _this.parents('#primary-navigation').length == 0
    ) {
        load_effect.menuOff();
    } else {
        load_effect.loader.show();
        var href = $(this).attr('href');
        $('.site').css('opacity', 0);
        setTimeout(function() {
            window.location = href;
        }, load_effect.duration);
    }
});

I think the best solution would be to create a child theme, dequeue that script and enqueue a copy of the script without that redirect:

<?php
// hook in late to make sure the parent theme's registration 
// has fired so you can undo it. Otherwise the parent will simply
// enqueue its script anyway.
add_action('wp_enqueue_scripts', 'override_functions_script', 100);
function override_functions_script()
{
    wp_dequeue_script('expositio-script');
    wp_enqueue_script('child-expositio-script', get_stylesheet_directory_uri().'/js/functions.js', array('jquery'));
}

And on your child functions.js, you could only redirect page if the link doesn't have fancybox class:

$('a').on('click', function(e) {
    e.preventDefault();
    var _this = $(this);
    // close mobile menu if it's open, redirect otherwise
    if (_body.hasClass('toggled-on') && _this.parents('#page').length == 1
        && _this.parents('#primary-navigation').length == 0
    ) {
        load_effect.menuOff();
    } else {
        load_effect.loader.show();
        var href = $(this).attr('href');
        $('.site').css('opacity', 0);
        if(!_this.hasClass('fancybox')) {  // only redirect if it doesn't have fancybox class
            setTimeout(function() {
                window.location = href;
            }, load_effect.duration);
        }
    }
});

Also, it would be good to report that to theme developer as they shouldn't have that code on a so generic rule.

  • God bless You! Thanks a lot, that was very hapefull! I will amke sure to report that code. Have a beautiful life :** – dajza bata Jul 13 '17 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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