• Hello, since i use several commercial plugins, i found out that my site loads a lot of unnecessary script. Things are loaded even in home page because of the wonderful wp_enqueue_script/style

    i wonder if there’s plugin to manage this so i can set in my site to load the script only when it needed…

    or do i have to code it manually ?

    i think wordpress need to address a design pattern so developer forced to create plugins with best practices.. or at least build better function so the script only load when the widget is loaded..

    Thanks

Viewing 1 replies (of 1 total)
  • J M

    (@hiphopinenglish)

    Why aren’t you loading your scripts conditionally?

    Here’s an answer I gave to a similar issue on WPSE.

    function js_custom() {
            if ( is_page('273') ) { // Here is where we sniff for specific elements
                wp_register_script( 'js_custom', get_template_directory_uri() . '/js/custom.js', false, null);
                wp_enqueue_script( 'js_custom' );
            }
    }
    add_action('wp_enqueue_scripts', 'js_custom', 50);

    Check out the Codex on Conditional Tags for a decent list of conditions where you may want to use scripts/styles.

Viewing 1 replies (of 1 total)
  • The topic ‘Maintain Scripts’ is closed to new replies.