Reply To: Make some pages templates conditional on mobile or not
I use this on my site to show a different single.php. I have a folder mobile in my theme folder with my mobile templates. I copied single.php, removed the get_sidebar and then added css when on mobile to style it better. This code works in functions.php.
`function mobile_filter_wp_template( $template ) {
$overridden_template = dirname( __FILE__ ) . ‘/mobile/mobile-single.php’ ;
if ( is_single() && wp_is_mobile() ) {
return load_template( $overridden_template );
} else {
return $template;
}
}
add_filter( ‘template_include’, ‘mobile_filter_wp_template’, 10, 2 );`
`function mobile_style() {
if ( is_single() && wp_is_mobile() ) {
echo ”
<style>
body {
width: 100%;
}
</style>”;
}
}
add_action(‘wp_head’, ‘mobile_style’);`
Use WP is_page to set conditions to specific pages https://codex.wordpress.org/Function_Reference/is_page