Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #3550
    kir pil
    Participant

    i like to see prettyphoto galleries on pc, and i also like to see SwipeBox galleries on tablets and mobiles.

    my site is responsive, so it’s possible to load prettyphoto on some @mediasets ( et max-width: 1200px) and SwipeBox on others @mediasets (et @media only screen (max-width: 479px)

    #3574
    Bartosz
    Keymaster

    Yes, but not using mediaqueries.

    There’s a rl_lightbox_args filter you can use in combination with WP native is_mobile() function

    #3577
    kir pil
    Participant

    thank you Bartosz. can you give a little help with rl_lightbox_args filter?

    #3581
    Bartosz
    Keymaster

    Ok, something like this:

    function custom_rl_lightbox_args($args) {
    	if (wp_is_mobile() === true) {
    		$args['script'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
    	} else {
    		$args['nivo'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
    	return $args;
    }
    add_filter('rl_lightbox_args', 'custom_rl_lightbox_args');

    This would use swipebox if site is displayed on mobile device and nivo if displayed on all others (desktop and devices not recognized as mobile)

    Just paste the code into functions.php of your theme.

    Good luck!

    #3582
    kir pil
    Participant

    thank you Bartosz. i paste the code on my functions.php but nothing happens. it’s still load prettyphoto on mobile

    function custom_rl_lightbox_args($args) {
    	if (wp_is_mobile() === true) {
    		$args['script'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
    	} else {
    		$args['prettyphoto'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
    	return $args;
    }
    add_filter('rl_lightbox_args', 'custom_rl_lightbox_args'); 
    }
    #3591
    kir pil
    Participant

    i fixed it using the Mobile Detect class http://mobiledetect.net/

    
    function custom_rl_lightbox_args($args) {
     require_once '/home/yourdomain/public_html/wp-content/plugins/wp-mobile-detect/mobile-detect.php';
     $detect = new Mobile_Detect();
     if ($detect->isMobile()) {
     $args['script'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
     }
     return $args;
    }
    add_filter('rl_lightbox_args', 'custom_rl_lightbox_args');
    #3592
    Bartosz
    Keymaster

    It’s a good, more reliable option. wp_is_mobile() works ok, but if you need more control this is the way to go.

    #5723
    Benuzar
    Participant

    I fight with exactly the same problem. I also pasted the posted code …

    function custom_rl_lightbox_args($args) {
    	if (wp_is_mobile() === true) {
    		$args['script'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
    	} else {
    		$args['nivo'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
    	return $args;
    }
    add_filter('rl_lightbox_args', 'custom_rl_lightbox_args');

    … in my function.php, but nothing changed. It doesn’t work.

    Unfortunately I’m not firm with php. Would anybody please explain step-by-step what I have to do using the solution with Mobile Detect class http://mobiledetect.net/ ?

    #5728
    Bartosz
    Keymaster

    It will not work like that.

    Please change this:
    $args['nivo'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
    into this:
    $args['script'] = 'nivo'; // swipebox, nivo, prettyphoto, fancybox

    #5764
    kir pil
    Participant

    i’am still searcing a way to make this code to work. any suggestion?

    
    function custom_rl_lightbox_args($args) {
    	if (wp_is_mobile() === true) {
    		$args['script'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
    	} else {
    		$args['script'] = 'prettyphoto'; // swipebox, nivo, prettyphoto, fancybox
    }
    	return $args;
    
    add_filter('rl_lightbox_args', 'custom_rl_lightbox_args'); 
    }
    
    #5876
    Benuzar
    Participant

    It seems to be a wrong placed curly bracket in your code.
    The last curly bracket should placed before “add_filter…”.

    function custom_rl_lightbox_args($args) {
    	if (wp_is_mobile() === true) {
    		$args['script'] = 'swipebox'; // swipebox, nivo, prettyphoto, fancybox
    	} else {
    		$args['script'] = 'prettyphoto'; // swipebox, nivo, prettyphoto, fancybox
    }
    	return $args;
    }
    add_filter('rl_lightbox_args', 'custom_rl_lightbox_args');

    @ Bartosz Arendt: Thanks for your help in Reply #5728

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.