Tuesday, 28 May 2013

How to disable fancybox on small screens

How to disable fancybox on small screens

I'm using the plugin "Fancybox for Wordpress" in WP 3.5.1. On small screens, I want to disable the fancybox-script. So, at top of header-file, I include a check for user agent, and sets global variable $is_mobile true or false. This works.
However, depending on this, I would like to add something like this to functions.php to disable the script on mobile devices.
$is_mobile;
function is_mobile() {
if ($is_mobile==true) {
    remove_action('wp_print_scripts', 'mfbfw_load');
    remove_action('wp_print_styles', 'mfbfw_css');
    remove_action('wp_head', 'mfbfw_init');

} else {$is_mobile = "false"; }

return $is_mobile;
}

add_action('wp_head', 'is_mobile', 1);
This doesn't work, maybe because functions.php is loaded before header.php. However, it also doesn't work if I include the check for useragent into the function.
Anyway, the variable $is_mobile is not recognized as a global in header.php.

No comments:

Post a Comment