Creating a custom template file in Sage9

I am trying to redirect mobile users to a custom blade template named mobile.blade.php using this:

function mobile_home_redirect()


if (wp_is_mobile() && is_front_page()) {

include(get_template_directory() . ‘/mobile/home.blade.php’);




add_action(‘template_redirect’, NAMESPACE . ‘\mobile_home_redirect’);

It was successful, but blade syntax not working. I need urgent help please.

Instead of:

include(get_template_directory() . ‘/mobile/home.blade.php’);

Use the template() helper function:


Thank you Webstractions, tried this but did’nt work. It redirects to the default homepage. i’m sure this is very close to the solution.

What i’m simply trying to do is call a custom homepage template for mobiles. Further help on this will be appreciated.

Thanks a lot.

Maybe you have to echo template('mobile.home')I think. I’m not quite sure how it is done, but I have seen some code around Discourse using it.

Don’t use template_redirect

use template_include

add_filter( 'template_include', 'my_callback' );
function my_callback( $original_template ) {
  if ( some_condition() ) {
    return SOME_PATH . '/some-custom-file.php';
  } else {
    return $original_template;