Title: Conditional wp_enqueue Function
Last modified: August 20, 2016

---

# Conditional wp_enqueue Function

 *  [Jami Gibbs](https://wordpress.org/support/users/jami0821/)
 * (@jami0821)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/conditional-wp_enqueue-function/)
 * Hi everyone!
 * I’m developing a new WordPress theme and I’m giving the user multiple slider 
   options. The sliders load different jquery files which I’d like to wp_enqueue
   depending on if that particular slider is chosen.
 * I have an options panel set up where the user can select the slider style they
   want. My question is how can I wp_enqueue a script conditionally after checking
   that they chose that option?
 * Here is what I have so far but it doesn’t seem to work:
 *     ```
       function jg_slider_content_scripts() {
       	$slider_choice == of_get_option('slider_choice');
   
       	if ( (is_front_page()) && ($slider_choice == 'content') ) {
   
       		wp_register_script('slides', get_template_directory_uri() . '/js/slides.min.jquery.js', 'jquery');
   
       		wp_enqueue_script('slides');
       	}
       }
       add_action('wp_print_scripts', 'jg_slider_content_scripts');
       ```
   
 * First, I’m trying to get the theme slider option the user has chosen. Then I’m
   checking if it’s both the front page and the slider choice variable equals ‘content’.
   If both of those conditions are true then it should spit out the jquery file 
   for the slider.
 * Can anyone point me in the right direction why this isn’t working?

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

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [Jami Gibbs](https://wordpress.org/support/users/jami0821/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/conditional-wp_enqueue-function/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
