WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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.

share|improve this question

You could have a try with wp_is_mobile():

if ( wp_is_mobile() ) {
  remove_action( 'wp_print_scripts', 'mfbfw_load' );
  remove_action( 'wp_print_styles', 'mfbfw_css' );
  remove_action( 'wp_head', 'mfbfw_init' );

You should also check with tablets since they might have a big resolution and hence not fall in your "small screen" condition. You should note that the User Agent string can be modified by any browser sending the request.

share|improve this answer

Directly under that script try:

$is_mobile = is_mobile();

share|improve this answer
Please add an explanation to your answer: why could that solve the problem? – toscho May 28 '13 at 10:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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