Create a mobile version of a WordPress website

Please note that this guide is for setting up an alternate mobile subdomain (or domain) which mirrors content from a parent website.

See the PixelPress projects for the RiAus Website Network using WordPress Multisite for this code in use.

This guide follows the steps listed below:

  1. Set up a parked domain (usually in cPanel)
  2. Add in a custom php browser agent detection and redirection script (in header.php or functions.php)
  3. Modify the wp-config file to to set our desired url as the blog and wp-admin url (see code below)
  4. Apply our desired theme or css based on the url being viewed/used (with the ‘WP Theme Switcher‘ plugin)

The code examples below are for the digitalcoffee.com.au domain.

  1. Create a parked domain (or subdomain)
    For example, my usual domain is digitalcoffee.com.au, I created a parked domain for m.digitalcoffee.com.au
    Important Note: As our mobile website will be a mirror of the parent websites content – uou are not actually adding/creating a ‘subdomain’, you are creating a ‘parked domain’.Make sure you set the ‘Domain Root’ for your parked mobile subdomain to be the same as the parent website with all the content for the mobile site.
    In my case the ‘Domain Root’ was ‘/public_html’
  2. Browser detection and redirection
    Yet to be finalised
  3. Add URL rewrite rules to the WordPress wp-config file
    Add the following rules to your wp-config fiule below the line with ‘define (‘WPLANG’, ”);’
    Remember this example is for digitalcoffee.com.au, you will need to add in your url’s.

    /*  Custom code for accomodating a mirror mobile subdomain of the parent website.
    This code changes the Blog & WP Admin URL's if the moobile subdomain is used.  */
    if ($_SERVER['HTTP_HOST'] == $localHost) {
     // Do nothing - Leave the WP_SITEURL & WP_HOME values unchanged
    }
    else {
     define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '');
     define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '');
    }
    
  4. Apply the desired theme based on the URL
    Download and install the ‘WP Theme Switcher‘ plugin.
    Once installed view the WP Theme Switcher settings page under ‘Settings’ and specify a url/uri for the appropriate themes avaiable in the your WP install.

Revisions

There are no revisions for this post.

Tags: , ,

No comments yet.

Leave a Reply