Created
October 26, 2012 19:24
-
-
Save plasticmind/3960891 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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