[done] Help with conitional metatag for iPad users

A place to make for-pay "CMS made simple" job offerings
Post Reply
casidougal
Forum Members
Forum Members
Posts: 98
Joined: Tue Jun 06, 2006 10:08 pm
Location: USA

[done] Help with conitional metatag for iPad users

Post 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!
Last edited by casidougal on Fri Nov 18, 2011 7:48 pm, edited 1 time in total.
tokr
Forum Members
Forum Members
Posts: 19
Joined: Sun Sep 16, 2007 3:15 am
Location: Beaverlodge, AB, Canada - near Grande Prairie

Re: Help with conitional metatag for iPad users

Post 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.
Last edited by tokr on Fri Nov 18, 2011 4:57 am, edited 1 time in total.
casidougal
Forum Members
Forum Members
Posts: 98
Joined: Tue Jun 06, 2006 10:08 pm
Location: USA

Re: Help with conitional metatag for iPad users

Post 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????
tokr
Forum Members
Forum Members
Posts: 19
Joined: Sun Sep 16, 2007 3:15 am
Location: Beaverlodge, AB, Canada - near Grande Prairie

Re: Help with conitional metatag for iPad users

Post 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}
Post Reply

Return to “Help Wanted (commercial)”