0

I've figured out how to show an element on mobile

<?php if(detectMobile()) { ?>
htmlcode
<?php } ?>

However i'm trying the opposite and want to HIDE an element on mobile. I know this is possible with css but in this case i don't want to use the display:none option because its using the same css like some other elements that should not be hidden on mobile. Also creating a unique css is not what i want in this case.

razz vazz
  • 13
  • 1
  • In this link you will found the answer https://stackoverflow.com/questions/4117555/simplest-way-to-detect-a-mobile-device – Josimar Apr 27 '20 at 13:08
  • I am assuming your function detectMobile() should work fine. And if you have added if check so whats the issue in checking the case in opposite manner or adding else case. Please close this question. – Mohd Belal Apr 27 '20 at 13:08
  • @MohdBelal just because it is an easy to answer question, does not mean it is a bad question and thus needs to be closed. There must have been a time when you did not know how to use an if else or not operator too... – LPChip Apr 27 '20 at 13:27
  • @LPChip FYI We have another same question pushed in stack as mentioned in comment above. Adding redundancy adds overhead to SO and nothing much. As a maintainer you need to check these areas as well. – Mohd Belal Apr 27 '20 at 17:27

1 Answers1

1

Simply change your if yes to an if no by adding a ! (not operator)

Your code becomes:

<?php 

if( !detectMobile() ) 
{ 
    ?>
    htmlcode
    <?
} 
?>

or alternatively, use an if else construction. Your code becomes:

<?php 

if( detectMobile() ) 
{ 
    // future code in case we must do something for mobile.
    ?>

    <?
} 
else 
{
    // if not mobile, then this code is being used.
    ?>
        htmlcode
    <?
}
?>
LPChip
  • 792
  • 1
  • 11
  • 25