Title: Conditional Loading &amp; Deferring JS
Last modified: December 17, 2016

---

# Conditional Loading & Deferring JS

 *  Resolved [P T](https://wordpress.org/support/users/pthomson87/)
 * (@pthomson87)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/conditional-loading-deferring-js/)
 * Hello,
 * It would be nice if the scripts and styles could be loaded on a conditional basis,
   or when shortcode is present on page. Currently they are loaded site-wide but
   not needed site wide.
 * Having an option to defer the loading of the scripts and/or styles in the footer
   would also be nice.
 * Other than that, it’s a great plugin.
 * Thanks,
    Paul

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [Craig at Smash Balloon](https://wordpress.org/support/users/craig-at-smash-balloon/)
 * (@craig-at-smash-balloon)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/conditional-loading-deferring-js/#post-8565282)
 * Hey Paul,
 * Loading of the scripts and styles on a conditional basis would be possible with
   adding some php to the functions.php file for your theme. For example, this would
   work:
 *     ```
       add_action( 'wp_enqueue_scripts', 'remove_ctf_resources', 20 );
       function remove_ctf_resources() {
       	if( !is_page(array( 'news', 'blog' )) ){
       		wp_dequeue_style('ctf_styles');
                       wp_enqueue_script('ctf_scripts');
       	}
       }
       ```
   
 * You would want to change the ‘news’ and ‘blog’ parts to meet your specific situation.
   Here is a link to how is_page() works: [https://developer.wordpress.org/reference/functions/is_page/](https://developer.wordpress.org/reference/functions/is_page/).
   You would just need to add the proper page slugs to the snippet.
 * As for your second request, the scripts should load in the footer. Are you seeing
   something different on your site?

Viewing 1 replies (of 1 total)

The topic ‘Conditional Loading & Deferring JS’ is closed to new replies.

 * ![](https://ps.w.org/custom-twitter-feeds/assets/icon-256x256.png?rev=2700808)
 * [Custom Twitter Feeds - A Tweets Widget or X Feed Widget](https://wordpress.org/plugins/custom-twitter-feeds/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-twitter-feeds/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-twitter-feeds/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-twitter-feeds/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-twitter-feeds/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-twitter-feeds/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Craig at Smash Balloon](https://wordpress.org/support/users/craig-at-smash-balloon/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/conditional-loading-deferring-js/#post-8565282)
 * Status: resolved