I am creating a new page template (which essentially i am taking bits and pieces from a new theme). I have called this template-flat.php

Now in functions.php I am looking for a conditional statement to load some new js and css only for template-flat.php instead of the ones loaded by the old theme.

Is there a way I can do this?


You can make use of the conditional tag is_page_template()

This Conditional Tag allows you to determine if you are in any page template. Optionally checks if a specific Page Template is being used in a Page. This is a boolean function, meaning it returns either TRUE or FALSE.

You can try something like

if( is_page_template( 'template-flat.php' ) ) {

    //Do something if the current template is template-flat.php


    //Do something else if the current template is not template-flat.php

  • thanks Pieter. Will this code also work if I am using the page template for custom post types?
    – JoaMika
    Feb 3 '15 at 19:04
  • This conditional tag will work regardless of post type. Whether or not your template will work with custom post type is up to the code inside the template :-) Feb 3 '15 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.