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.