Dynamically change WordPress url or theme if UserAgent is iPhone

Is there a way to do this?

My site is http://kennethreitz.com . It's run by some moderate PHP on top of Wordpress.

My options are to determine if the user is using an iphone and if they are either

a) tell wordpress to download another "theme" I wrote. b) if this is not possible, do a different installation of wordpress on the subdomain (i.kennethreitz.com) which is running from the same database as the other theme.

I would rather do A for SEO reasons.

Any ideas?

+2


source to share


5 answers


http://www.nathanrice.net/blog/serve-ie6-visitors-the-default-wordpress-theme/ demonstrates how to use a template filter to dynamically change a WordPress theme (IE6 in this case, but it could be a mobile custom agent):



add_filter('template', 'serve_default_to_iesix');
add_filter('option_template', 'serve_default_to_iesix');
add_filter('option_stylesheet', 'serve_default_to_iesix');

function serve_default_to_iesix($theme) {
    if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false)
        $theme = 'default';
    return $theme;
}

      

+12


source


Have you looked at iWPhone ?

It is a WordPress plugin and theme that automatically takes care of detecting if the visitor is from an iPhone and formats accordingly. It's pretty easy to replace your own iPhone CSS if you like, although the main theme is pretty decent.



There's also WPTouch , which looks to be similar in functionality but is slightly more recent and has better administration integration.

+3


source


Here is a Wordpress plugin that supports different themes for different browsers (e.g. iPhone):

http://code.kuederle.com/browserbasedthemes

+2


source


I have no experience with WordPress, but the iWPhone + theme plugin looks like it might work

0


source


You can't do either A or B out of the box.

Loading another theme is not possible because this option is stored in the database in the wp_Options table. This parameter is independent of the user. Option B is not an option, since you will be sharing the same database, you will be choosing the same value for the topic.

If you look in the wp_options table, the theme parameter will be found in the entry corresponding to "template" and "style sheet".

0


source







All Articles