Drupal 7 hide block for mobile devices using browscap

Sun, 07/07/2013 - 23:11 -- meladawy

Besides the great responsive frameworks and themes provided by Drupal like Adaptivetheme, Omega...etc there is a strong need for browscap. Browscap is a very simple module that provide you with browscap_get_browser() function, which return more details about the current user agent & browser. Lets use it to hide a specific block in mobile devices


1- Open your block settings from Structure > Blocks > Configure
2- From visibility settings , select "Pages on which this PHP code returns TRUE (experts only)"
3- And inside the text area add the following code

<?php 
$mobile_agent = browscap_get_browser() ;
if($mobile_agent['ismobiledevice'] == "false"){ // if user agent is not a mobile device, then show me the block 
return true; 
} 
?> 



We are done... :) Good luck !

Comments

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.