Reputation: 4557
I am new to wordpress plugin development, but any how I have developed two shortcodes i.e. [MY_SHORTCODE]
and [MY_SHORTCODE_MOBILE]
, both are working fine but now I want to do one enhancement in it, that is, I want to write a new shortcode which detect the device
, if the detected device is mobile than I want to call the shortcode [MY_SHORTCODE_MOBILE]
otherwise I want to call [MY_SHORTCODE]
. How can I do this ? please help me guys .
Upvotes: 1
Views: 3398
Reputation: 3240
i got it your problem that you want to run short code base on browser or mobile device.
Download php file for mobile detect code and put below code where do you want to run short code
<?php
$useragent=$_SERVER['HTTP_USER_AGENT'];
if(preg_match('/copy paste mobile detect code here from detectmobilebrowser.php',substr($useragent,0,4)))
{
//header('Location: http://detectmobilebrowser.com/mobile');
// that code run for mobile device
echo do_shortcode("[MY_SHORTCODE_MOBILE]");
}
else{
// that code run for browser
echo do_shortcode("[MY_SHORTCODE]");
}
?>
Upvotes: 0
Reputation: 26722
you can do it via a plugin Mobile Detector
or if you want to create your own you can start by using mobile detection library(PHP)
Upvotes: 1