Page 1 of 1

[done] Help with conitional metatag for iPad users

Posted: Thu Nov 17, 2011 11:41 pm
by casidougal
Hi,

I need to hire someone a lot smarter than myself to find a way to accomplish the following:

For just iPad users, I want the following meta tag to be applied:

Code: Select all

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
For all other visitors including iPod, iPhone, Android and all PC and Mac visitors I do not want that meta tag to be applied.

Don't laugh at my attempt but here's what I've tried without success . . . the code keeps showing up at the top of my web page or I get an error. I've also tried creating a user defined tag with the code to no avail.

I'm glad to pay someone to show me how to do this correctly, here's my code which I placed right after the <head> tag:

Code: Select all

{literal}
strstr($_SERVER['HTTP_USER_AGENT'],'iPad')
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPad')){
document.write("<meta name=\"\viewport\"\ content=\"\width=device-width, initial-scale=1, maximum-scale=1\"\ />");
} else {
echo ' ';
}
{/literal}
Thank you!

Re: Help with conitional metatag for iPad users

Posted: Fri Nov 18, 2011 2:13 am
by tokr
What you need to do is create a user defined tag with the detection code in it. I wrote such a UDT that I use to detect mobile devices.

Re: Help with conitional metatag for iPad users

Posted: Fri Nov 18, 2011 2:54 am
by casidougal
tokr wrote:What you need to do is create a user defined tag with the detection code in it. I wrote such a UDT that I use to detect mobile devices.
Thanks for the reply . . . you missed in my post where I said
"I've also tried creating a user defined tag with the code to no avail."
It still doesn't work when I do that . . . I must have something wrong in the PHP????

Re: Help with conitional metatag for iPad users

Posted: Fri Nov 18, 2011 4:38 am
by tokr
Here is my user agent UDT:

Code: Select all

//Code to get the user's user agent information.
$agent = ($_SERVER["HTTP_USER_AGENT"]);
$accept = ($_SERVER["HTTP_ACCEPT"]);

if (preg_match("/sony|symbian|samsung|mobile|windows ce|epoc|opera|mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up

\.link|audiovox|nokia|blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-|portalmmm|blazer|avantgo|danger|palm|series60|

palmsource|pocketpc|smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android/i", $agent) || 

preg_match("/text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml/i", $accept)) {
    $result = true;
} else {
    $result = false;
}
$is_mobile=$result;
$smarty->assign('is_mobile',$is_mobile);
I named the UDT is_mobile and in the template I first call the UDT and then use the variable:

Code: Select all

{is_mobile}
{if $is_mobile}do something{/if}