I’m building a website in WordPress which has a separate mobile theme (this obviously uses the same database as the main site). The mobile theme is a child of the main theme, to maximize code reuse.
I downloaded a mobile detection script that works pretty well, but I can’t figure out how to switch to the mobile theme only for the current user, with an option to link to the full website.
I don’t want to create a multisite for this – it seems like an overkill (and there’s the duplicate content issue).
I tried two ways:
- themeswitch: Redirect to
http://example.com/?theme=mobile_theme
– not working -
a weird solution I found somewhere on the web:
add_filter( 'template', 'wpse_49223_change_theme' ); add_filter( 'option_template', 'wpse_49223_change_theme' ); add_filter( 'option_stylesheet', 'wpse_49223_change_theme' ); function wpse_49223_change_theme($theme) { include 'script/Mobile_Detect.php'; $detect = new Mobile_Detect(); if ( $detect->isMobile() ) $theme = 'pinnacle_mobile'; return $theme; }
This is not working either.
Does anyone have a working solution to this?
Not sure if applicable for your site. But one common solution to this is media queries.
http://cssmediaqueries.com/
Basically its if “mobile device” show this css else show “normal css”
Another idea is to redirect to *mobile.yourdomain.com* when a mobile user connects. And having your mobile wordpress theme on that domain.
The solution was indeed to use the Theme Switch plug-in.
There are two things of importance here:
Note that the theme parameter has to be the actual theme name, not the directory name. It’s case sensitive and uses
+
instead of spaces.