Title: Conditional wp_enqueue with is_page_template
Last modified: August 20, 2016

---

# Conditional wp_enqueue with is_page_template

 *  [jeanmeslier](https://wordpress.org/support/users/jeanmeslier/)
 * (@jeanmeslier)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/conditional-wp_enqueue-with-is_page_template/)
 * Hello all,
 * I am trying to do a conditional enqueue of scripts, to cut down on load time,
   but this code in functions.php does not seem to be working and I can’t figure
   out what it is that I’m missing. The non-conditional scripts are enqueuing, but
   the conditional ones arent loading on the pages they are supposed to, or any 
   pages at all, for that matter.
 * Any help is appreciated. Thanks.
 *     ```
       function my_ck_scripts()
       {
       	wp_register_script ('jquerymin', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');
       	wp_register_script ('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js');
       	wp_register_script( 'caseykaplan', get_template_directory_uri() . '/js/ck.js');
       	wp_enqueue_script('jquerymin');
       	wp_enqueue_script('jqueryui');
       	wp_enqueue_script('caseykaplan');
   
           if(is_page_template( array('archive-news.php', 'archive-exhibitions.php', 'category-art-fairs.php', 'category-artist-news.php', 'category-events.php', 'category-gallery-news.php', 'category-upcoming.php') )) {
                   wp_register_script('masonry', get_template_directory_uri() . '/js/jquery.masonry.min.js');
                   wp_enqueue_script('masonry');
           }
   
            if(is_page_template( array('exhibition-images-page.php', 'artist-images-page.php') )) {
                   wp_register_script('bxslider', get_template_directory_uri() . '/js/jquery.bxSlider.min.js');
                   wp_enqueue_script('bxslider');
           }
   
       }
   
       add_action('wp_enqueue_scripts','my_ck_scripts');
       ```
   
 * Josh

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * (@wordpressismypuppet)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/conditional-wp_enqueue-with-is_page_template/#post-2901856)
 * I don’t believe that is_page_template() will accept an array… only a string. 
   See here:
 * [http://codex.wordpress.org/Function_Reference/is_page_template](http://codex.wordpress.org/Function_Reference/is_page_template)
 * So basically you’ll have to change this line:
 * `if(is_page_template( array('archive-news.php', 'archive-exhibitions.php', 'category-
   art-fairs.php', 'category-artist-news.php', 'category-events.php', 'category-
   gallery-news.php', 'category-upcoming.php') )) {`
 * to:
 * `if(is_page_template( 'archive-news.php' ) || is_page_template( 'archive-exhibitions.
   php' ) || ...`
 * And the same with the other if statement.
 *  [reneequinn](https://wordpress.org/support/users/reneequinn/)
 * (@reneequinn)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-wp_enqueue-with-is_page_template/#post-2902162)
 * Thanks Puppet master – worked for me.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Conditional wp_enqueue with is_page_template’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [enqueue](https://wordpress.org/support/topic-tag/enqueue/)
 * [is_page_template](https://wordpress.org/support/topic-tag/is_page_template/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [reneequinn](https://wordpress.org/support/users/reneequinn/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/conditional-wp_enqueue-with-is_page_template/#post-2902162)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
