Conditional Page Template not working

You need to run this code in an action hook rather than directly in the functions.php file. Take a look at the Action Reference page in the Codex and determine at which point you want this script to run. Whatever action you choose will end up looking something like this:

add_filter( 'template_include', 'check_page_template', 99 );

function check_page_template( $template ) {
  if( is_page_template( 'template-flat.php' ) ) {
    // other code
  } else {
    require_once(functions . '/shortcodes.php');
  }
  return $template;
}

Leave a Comment