Vũ Trọng Quang Vũ Trọng Quang - 1 month ago 11
PHP Question

Create version mobile for wordpress theme

I have a absolute page for mobile on wordpress theme.

About detecting mobile and tablet, I have done.

How can I redirect to subfolder or file for mobile when I use mobile or tablet.

Thanks all.

Answer

Well there are 2 ways to redirect to mobile subdirectory :

1) Simplest and easiest :

Use following javascript , place this at start of your html page

<script type="text/javascript">
  <!--
  if (screen.width <= 800) {
    window.location = "http://m.domain.com";
  }
  //-->


</script>

2) A bit complex editing .htaccess file :

# Check for mime types commonly accepted by mobile devices
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ http://m.domain.com%{REQUEST_URI} [R,L]

tis rewrite your URL to mobile subdirectory.

Comments