Title: Cannot optimize mobile theme
Last modified: August 31, 2016

---

# Cannot optimize mobile theme

 *  [nickmobmethod](https://wordpress.org/support/users/nickmobmethod/)
 * (@nickmobmethod)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/cannot-optimize-mobile-theme/)
 * Hi!
 * Installed AO 2.0.2.
    I’m using custom mobile swithing plugin: it detects mobile
   browsers and switches to mobile WP theme. The problem is: AO works fine on desktop
   version ([http://dev2.kuponarama.ru/](http://dev2.kuponarama.ru/)) but on mobile(
   [http://m.dev2.kuponarama.ru/](http://m.dev2.kuponarama.ru/)) it works only for
   html and inlined CSS and JS – so it cannot optimize external CSS (for example
   with URL “/wp-content/themes/mobile/css/all.css”).
 * Some theme switching code:
 *     ```
       case "m.dev2.kuponarama.ru":
       			define('WP_HOME', 'http://m.dev2.kuponarama.ru');
       			define('WP_SITEURL','http://m.dev2.kuponarama.ru');
       			//define('WP_CONTENT_URL','http://m.dev2.kuponarama.ru/wp-content');
       			break;
       ```
   
 * Changing theme:
 *     ```
       /**
        * @return mobile theme name
        */
       function kuponarama_getMobileTheme() {
       	switch($_SERVER["HTTP_HOST"]) {
       		case "m.kuponarama.ru":
       		case "m.dev.kuponarama.ru":
       		case "m.dev2.kuponarama.ru":
       			return "mobile";
       		case "dev.kuponarama.ru":
       		case "kuponarama.ru":
       		case "www.kuponarama.ru":
       			return "clipper-child";
       	}
       }
   
       function ts_get_template($template) {
       	$theme = kuponarama_getMobileTheme();
       	if (empty($theme)) {
       		return $template;
       	}
       	$theme = ts_get_one_theme($theme);
       	if (empty($theme)) {
       		return $template;
       	}
       	// Don't let people peek at unpublished themes.
       	if (isset($theme['Status']) && $theme['Status'] != 'publish')
       	return $template;
       	return $theme['Template'];
       }
       add_filter('template', 'ts_get_template');
   
       function ts_get_stylesheet($stylesheet) {
       	$theme = kuponarama_getMobileTheme();
       	if (empty($theme)) {
       		return $stylesheet;
       	}
       	$theme = ts_get_one_theme($theme);
       	// Don't let people peek at unpublished themes.
       	if (isset($theme['Status']) && $theme['Status'] != 'publish')
       	return $stylesheet;
       	if (empty($theme)) {
       		return $stylesheet;
       	}
       	return $theme['Stylesheet'];
       }
       add_filter('stylesheet', 'ts_get_stylesheet');
   
       // helper function to replace get_theme()
       function ts_get_one_theme($theme) {
       	$themes = wp_get_themes();
       	if (array_key_exists($theme, $themes))
       	return $themes[$theme];
       	return NULL;
       }
       ```
   
 * [https://wordpress.org/plugins/autoptimize/](https://wordpress.org/plugins/autoptimize/)

Viewing 16 replies (of 16 total)

[←](https://wordpress.org/support/topic/cannot-optimize-mobile-theme/?output_format=md)
[1](https://wordpress.org/support/topic/cannot-optimize-mobile-theme/?output_format=md)
2

 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/cannot-optimize-mobile-theme/page/2/#post-7295367)
 * frustrating we haven’t been able to get this working! do let me know if you ever
   find out what was going on!
 * I might do some tests with switching themes like that in the future.
 * frank

Viewing 16 replies (of 16 total)

[←](https://wordpress.org/support/topic/cannot-optimize-mobile-theme/?output_format=md)
[1](https://wordpress.org/support/topic/cannot-optimize-mobile-theme/?output_format=md)
2

The topic ‘Cannot optimize mobile theme’ is closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

 * 16 replies
 * 2 participants
 * Last reply from: [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/cannot-optimize-mobile-theme/page/2/#post-7295367)
 * Status: not resolved