Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Joshua David Nelson

    (@joshuadnelson)

    Jario,

    Yes, there is a built-in way to do this when you enqueue a script – by setting it dependent on another script, like jquery, it will only be loaded if jquery has been loaded.

    That said, while Scripts-to-footer should, in theory, place everything in the footer in the same order – there are plenty of scripts that actually need to be placed in the header in order for page elements or in-line scripts to work. That might be the case for your issue.

    You can either disable the plugin on the specific page that is having the issue, or you can use this tutorial to place specific scripts in the header. Just be sure you are grabbing the correct scripts and placing them in the correct order.

    Cheers,
    Joshua

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Hi Joshua,

    Thanks for the reply.

    If I did like this:

    function jdn_deregister_scripts() {
    	wp_deregister_script( 'jquery.js' );
    	wp_deregister_script( 'jquery-migrate.min.js' );
    }
    add_action( 'wp_print_styles', 'jdn_deregister_scripts', 100 );
    
    function jdn_head_scripts() { // The html for the script that will be placed in the header
    ?>
    	<script type='text/javascript' src="/wp-includes/js/jquery/jquery.js"></script>
    	<script type='text/javascript' src="/wp-includes/js/jquery/jquery-migrate.min.js"></script>
    <?php
    }
    add_action( 'wp_head', 'jdn_head_scripts' );

    … but I got twice “jquery.js” and “jquery-migrate.min.js”.
    15 .js file are loaded.

    But if I only write

    … wp_deregister_script( 'jquery' ); …
    Only 8 js are loaded !!!

    So, how can I choose only a few files not to be desregistred ?

    Thanks.

    Plugin Author Joshua David Nelson

    (@joshuadnelson)

    Ah, yes. Well, jquery is a popular script and it is often referenced by others as being dependent on it. This means that those scripts essentially piggy-back on jquery and only load after it.

    There are a multitude of places and ways to enqueue a script, and they could be from one/more plugins or your theme, so it is very hard to diagnose a solution for a specific combination of theme/plugins that may be dependent on jquery.

    My suggestion would be to either take the easier route and disable the plugin on the specific page(s) where you’re having the issue – keeping them in the header. Or, a more lengthy process would be to deactivate all your other plugins, then activate theme one-by-one and figure out where the specific script is registered, deregister it similar to above and re-register it without the jquery dependency. The latter option is not exactly standard procedure though, and could cause issues should you ever deactivate this plugin and the order gets mixed up again.

    It could also be that what you need is a plugin to minify your scripts instead of this plugin to move them to the footer.

    Hope that helps!
    Joshua

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Hi,

    Unfortunately Cookie Consent plugin must work on every page, so I cannot disable the plugin for only just one page.

    I also minify the files with W3 Cache, but dependent files also disappear. It seems like not only something-jquery.js files are deregister, I think that js files dependent of jquery core are not loaded.

    I’ll make a list of all files with and without deregistering and then check how many are missing.

    Thanks.

    Plugin Author Joshua David Nelson

    (@joshuadnelson)

    Jairo,

    Sounds complicated!

    I’m happy to help with getting my plugin to work and debugging any issues or conflicts that you find. It sounds like Script-to-Footer is working as designed, but you’re trying to utilize it for a very custom, specific purpose. This plugin is definitely useful, but it is also broad-stroke in its approach. Trying to narrow it onto one script over others is certainly possible with the filters and options built-in, but I would beware of “using a shotgun where a scalpel is necessary,” if that makes sense.

    That said, this support forum is really focused on the plugin functionality itself and I can’t devote much (free) time to customizing plugins for a specific site, as I’m sure you can understand. If you’d like to discuss hiring me to customize or audit your site, we can get into more specific solutions.

    Let me know if there is anything related to Scripts-to-Footer plugin in the meantime.

    Best,
    Joshua

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Hi,

    The plugin is great and it help us to achieve more points at Google Page Speed Test.

    Unfortunately there are many plugins which uses jQuery and they place small scripts between head and footer.
    As we know, jQuery must be loaded before all of them but if it is deregistered some other scripts are missing.

    I will fix it like this:

    1- make a list of all scripts before deregistering jQuery
    2- make a list after deregistering jQuery
    3- add Jquery at the head using add_action( 'wp_head', …
    3- add missing scripts at the footer using add_action('wp_footer',…

    Greetings

    Plugin Author Joshua David Nelson

    (@joshuadnelson)

    Jairo,

    That sounds like a good plan. It seems like you have quite a few scripts that need to be in the header, and may or may not be dependent on jquery. If it turns out that the majority of your scripts are dependent on jquery, and they need to be loaded in the header, I would suggest not using this plugin.

    Instead, I would de-enqueue the scripts you want in the footer, and then re-enqueue them with the $in_footer set to true. This will place those scripts into the footer automatically. Unfortunately, this can’t be done as default for all scripts because scripts can be called from multiple places within themes and plugins, which is why this plugin disables a few hooks, forcing all scripts in the footer.

    Does that make sense? Hope that helps!

    Cheers,
    Joshua

    Thread Starter Jairo Ochoa

    (@jairoochoa)

    Thanks Joshua, I’ll check it.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘jQuery’ is closed to new replies.