Support » Plugin: Custom Twitter Feeds » Conditional Loading & Deferring JS

  • Resolved Paul Thomson

    (@pthomson87)


    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

    (@craig-at-smash-balloon)

    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/. 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.