Reputation: 11
Here is the current code I have placed in the header.php file on our Wordpress site:
<script type="text/javascript">
<!--
if (screen.width <= 700) {
window.location = "http://m.domain.com";
}
//-->
</script>
This issue is, this redirects all pages of our site to the landing page. I only want the 3 of our pages to be redirected. Can I redirect pages to our mobile version by their page id? (I want to avoid using a plugin for this.) If so, how would I write this?
Upvotes: 0
Views: 213
Reputation: 1574
var pageName = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
if (screen.width <= 700 && (pageName == 'filename1' || pageName == 'filename2' || pageName == 'filename3' ))
Upvotes: 0
Reputation: 1554
Typically this is done server side and the determination is made by reading the user-agent header. Mobile Detect is a PHP library I've had good luck with.
Upvotes: 0