-
AuthorPosts
-
December 7, 2013 at 1:03 am #197173
i need to include a php mobile detection detection script on the home page of my site, but not in the header or footer (doesn’t need to be on every page, just the home page. I tried adding it to a Text Box but it strips the code out.
<?php if(isset($_GET['nomobile'])){ echo ""; } else { echo "<script src='http://mysite.com/custom/detectmobilebrowser.js'></script>"; } ?>
December 7, 2013 at 4:21 am #197243Hi Tech!
You can’t add PHP code in a Page/Post content, put in the header but wrap it inside this conditional tag:
<?php if(is_home()){ if(isset($_GET['nomobile'])){ echo ""; } else { echo "<script src='http://mysite.com/custom/detectmobilebrowser.js'></script>"; } } ?>
That way that code will only run in the home page.
Best regards,
JosueDecember 7, 2013 at 5:23 pm #197309what am i doing wrong? in a text box i added, didn’ t go into the Visual View and just hit save. it took this
<?php if(is_home()){ if(isset($_GET['nomobile'])){ echo ""; } else { echo "<script src='http://mysite.com/custom/detectmobilebrowser.js'></script>"; } } ?>
and it comments out the php and returns
<!--?php<br /-->if(is_home()){ if(isset($_GET['nomobile'])){ echo ""; } else { echo "<script type="text/javascript" src="http://mysite.com/custom/detectmobilebrowser.js"></script>"; } } ?>
December 7, 2013 at 5:36 pm #197322You can’t add PHP code in a Page/Post content (Text box), my recommendation was to put it in the header.php file.
As a side note, if you insist in putting the code in the actual Page you can do it, but you’d need to rely on a plugin: http://wordpress.org/plugins/insert-php/
Cheers!
JosueDecember 7, 2013 at 6:00 pm #197343This reply has been marked as private.December 7, 2013 at 6:03 pm #197346Did it work?
Regards,
JosueDecember 7, 2013 at 6:09 pm #197348This reply has been marked as private.December 7, 2013 at 7:26 pm #197399This reply has been marked as private.December 7, 2013 at 8:55 pm #197418Hey!
I see, try with this instead:
<?php if(is_home() && isset($_GET['nomobile']){ echo ""; } else { echo "<script src='http://lapolla.com/custom/detectmobilebrowser.js'></script>"; } ?>
Regards,
JosueDecember 9, 2013 at 7:29 pm #198163thanks josue, although this code will redirect me from teh mobile to the desktop then back to the mobile instantly. I think i may have to tool this a bit or write something more extensive to fit different scenarios. thanks for your help so far
December 9, 2013 at 7:33 pm #198166Yes, i think it would be a matter of tweaking and testing, for further information about Conditional Tags refer to this link: http://codex.wordpress.org/Conditional_Tags
Cheers!
JosueMarch 8, 2014 at 12:01 am #234035This reply has been marked as private.March 8, 2014 at 12:26 am #234049Hey!
The script code is appearing in the wrong place (first line):
view-source:http://www.lapolla.com/It should be inside the <head></head> tag.
Best regards,
JosueMarch 8, 2014 at 12:29 am #234052This reply has been marked as private.March 8, 2014 at 12:33 am #234056Hey!
I don’t quite understand how it was working before, where does nomobile come from?
Best regards,
JosueMarch 8, 2014 at 12:38 am #234060This reply has been marked as private.March 8, 2014 at 10:03 pm #234255Hey!
Thank you for the question. I hope all is well with you today.
If you want a mobile redirect for your homepage, please use this plugin: http://wordpress.org/plugins/wp-mobile-detect/faq/
Refer to this link for more info: https://kriesi.at/support/topic/homepage-redirect-on-mobile-sites/
Best regards,
IsmaelMarch 11, 2014 at 11:30 pm #235953thanks ismael & josue! works like a charm. you all can mark this closed
-
AuthorPosts
- The topic ‘include php detection script not in header’ is closed to new replies.