Weblog Archive

Go mobile

Sat, 26 Jan 2008 at 19:22 | Filed under Design, Mobile, Noteworthy, Plugins

Taking Amit’s idea to the next level, here’s how you can make a mobile version of your blog.

Create a folder named m in your blog root—if you have a self-hosted blog. Dump a file named index.php with the following content in it:

  1. <?php
  2. header('HTTP/1.1 301 Moved Permanently');
  3. header( 'Location: http://www.google.com/reader/m/view/feed/http://ckunte.com/feed/atom' ) ;
  4. ?>
  5.  
  6. Download this example: /inputfiles/m.txt

Be sure to replace my site's feed address with yours in the code above. Your mobile blog version would now be accessible at this address, for example: yoursite.com/m (or yoursite.com/blog/m depending upon where you created the m subfolder on your host).

I am averse to creating a sudomain just for this, but if you still prefer a subdomain like address, here’s a plugin code I just whipped up.1

  1. <?php
  2. /*
  3. Plugin Name: Mobile version via Google Reader
  4. Plugin URI: http://ckunte.com/
  5. Description: m. subdomain address is redirected to google's mobile version.
  6. Author: Chetan Kunte
  7. Version: 1.0
  8. Author URI: http://ckunte.com/wordpress
  9. */
  10.  
  11. if ( !strstr( $_SERVER['HTTP_HOST'], 'm.' ) )
  12. return;
  13.  
  14. header('HTTP/1.1 301 Moved Permanently');
  15. header('Location: http://www.google.com/reader/m/view/feed/http://' . trailingslashit(substr($_SERVER['HTTP_HOST'], 2)) . 'feed/atom');
  16. exit();
  17.  
  18. ?>
  19.  
  20. Download this example: /inputfiles/moplug.txt

Download the file above2, and rename it to, say, moplug.php and upload it to wp-content/plugins folder. Your mobile site would now be accessible at m.mysite.com—all this without having to create a subdomain.

  1. Do note that I haven’t been able to test this on my host, since I have a subdomain related problem at the moment, but I believe this code would work. []
  2. Make sure there are no empty spaces after ?> in both the code snippets []
[ Ads ]

Related posts

Following list is auto-generated, based on this post's context as possibly related. You may, however, occasionally find some in this list unrelated, but nevertheless, we sincerely hope that you'll enjoy them too.

5 responses to “Go mobile”

  1. Amit Agarwal said:

    Chetan, this is absolutely brilliant.

    You subdomain trick works perfect. See http://m.labnol.org/

  2. Chetan said:

    Hi Amit, glad to know it’s useful.

  3. Creating a Mobile Version of your Blog | DesiPundit said:

    [...] Amit Agarwal offers a ten-second solution with the help of Google Reader. Chetan Kunte takes it a step further with a simple PHP index file or better still, a WordPress plugin. [...]

  4. Thejesh GN said:

    Very cool. Let me try it.

  5. नुक्ताचीनी » कड़ियाँ » सप्ताह 06 के स्वादिष्ट पì said:

    [...] गो मोबाइल: अपने ब्लॉग का मोबाईल संस्करण बनायें [...]