[SOLVED] identify if page being viewed in a mobile device

Boris99
14 years ago
Hi,

I have various photos etc that are included in website pages using php 'include' code (using sourcerer), and these aren't showing very well on mobiles. The code is in the articles themselves, not in modules.

If I want this code to be different for mobile devices, is there a (php?) variable or other way of picking up whether the article is being viewed in a mobile so I can use this in my include file?

(An example can be seen at page www.italythisway.com/places/lake-garda.php where on a ipod the top picture and hotel box and google ads is too wide for the screen - I want to remove the hotel search and the google ads on mobile devices)

Cheers!
dryabov
14 years ago
Just test _MJ constant:
if(defined('_MJ')) {
// mobile
} else {
//desktop
}
Boris99
14 years ago
Exactly what I needed
Thanks very much
bnighter
12 years, 9 months ago
Is this .php code?
I am using this defined('_MJ') in frontpage.php and it does not appear to detect in my kindle. I am looking for some php code to call to determine if the user is a mobile device.
brewtondaniel2
12 years, 9 months ago
This is, by far, the easiest method to handle cell phone users. Instead of worrying whether they can or cannot see your pages, simply put a link somewhere near the top of the page that points to your mobile version. Then the readers can self-select whether they want to see the optimized version or continue with the normal version .
Increase Website Hits

By continuing to use this site you consent to the use of cookies on your device as described in our cookie policy unless you have disabled them. This site will not function correctly without cookies.

I accept cookies from this site.