Skip to content

Instantly share code, notes, and snippets.

@plasticmind
Created October 26, 2012 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plasticmind/3960891 to your computer and use it in GitHub Desktop.
Save plasticmind/3960891 to your computer and use it in GitHub Desktop.
// Register our _mobile query variable
add_filter('query_vars', 'sr_mobile_var');
function sr_mobile_var($public_query_vars) {
$public_query_vars[] = '_mobile';
return $public_query_vars;
}
// Catch all /m/ requests and rewrite them as mobile
add_rewrite_rule('^m/([^/]*)?','$matches[1]&_mobile','top');
add_filter( 'template_include', 'sr_mobile_template_include' );
function sr_mobile_template_include( $template ) {
if ( !isset( $wp_query->query_vars['_mobile'] ) )
return $template;
// Template path--will eventually use this for testing pages...
$mobile_template_path = get_stylesheet_directory() . '/mobile/home.php';
//$mobile_template_path = get_stylesheet_directory() . '/mobile/' . TEMPLATE??? . '.php';
// Return that path if a readable file exists. Otherwise, return the normal template
return is_file( $mobile_template_path ) && is_readable( $mobile_template_path ) ? $mobile_template_path : $template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment