{"id":2113397,"date":"2011-06-03T11:18:38","date_gmt":"2011-06-03T11:18:38","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/conditional-wp_enqueue-function\/"},"modified":"2016-08-20T00:39:41","modified_gmt":"2016-08-20T00:39:41","slug":"conditional-wp_enqueue-function","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/conditional-wp_enqueue-function\/","title":{"rendered":"Conditional wp_enqueue Function"},"content":{"rendered":"<p>Hi everyone!<\/p>\n<p>I&#8217;m developing a new WordPress theme and I&#8217;m giving the user multiple slider options.  The sliders load different jquery files which I&#8217;d like to wp_enqueue depending on if that particular slider is chosen.<\/p>\n<p>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?<\/p>\n<p>Here is what I have so far but it doesn&#8217;t seem to work:<\/p>\n<pre><code>function jg_slider_content_scripts() {\n\t$slider_choice == of_get_option(&#039;slider_choice&#039;);\n\n\tif ( (is_front_page()) &amp;&amp; ($slider_choice == &#039;content&#039;) ) {\n\n\t\twp_register_script(&#039;slides&#039;, get_template_directory_uri() . &#039;\/js\/slides.min.jquery.js&#039;, &#039;jquery&#039;);\n\n\t\twp_enqueue_script(&#039;slides&#039;);\n\t}\n}\nadd_action(&#039;wp_print_scripts&#039;, &#039;jg_slider_content_scripts&#039;);<\/code><\/pre>\n<p>First, I&#8217;m trying to get the theme slider option the user has chosen.  Then I&#8217;m checking if it&#8217;s both the front page and the slider choice variable equals &#8216;content&#8217;.  If both of those conditions are true then it should spit out the jquery file for the slider.<\/p>\n<p>Can anyone point me in the right direction why this isn&#8217;t working?<\/p>\n","protected":false},"template":"","class_list":["post-2113397","topic","type-topic","status-closed","hentry","topic-tag-conditional","topic-tag-wp_enqueue"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2113397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2113397\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=2113397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}