Support

Account

Home Forums Add-ons Repeater Field Putting jQuery in footer

Solved

Putting jQuery in footer

  • I am in the middle of optimising my site for mobile and noticed that when I include the acf-repeater add-on that it puts jquery in the head. I think I found the function that puts it there :

    foreach( $scripts as $script )
    		{
    			wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->settings['version'] );
    		}
    

    but it doesn’t have the $in_footer parameter. Can I just put it there or if there a specific reason to have jquery in the document head? Also I would rather not hack the plugin. I don’t suppose there is a function that could override this?

    • Elliot

    • November 9, 2013 at 9:55 am

    Hi @mantismamita

    Thanks for the feedback. All ACF scripts and styles are included in the head tag, this is just a personal preference.

    Your mobile optimization, is this for the front end of the back end?

    Thanks
    E

  • Hi @elliot,
    It’s for the front end. I’m not too worried about the back end. But it makes a significant difference if I remove the add-ons folder containing acf-gallery and acf-repeater which add jquery and jquery migrate in the head tag.

    • Elliot

    • November 11, 2013 at 3:58 pm

    Hi @mantismamita

    Thanks for the info. For your case, what would be the perfect solution?

    Thanks
    E

  • Hi @elliot,
    Ideally a function to override it’s position in the header so that the plugin would be intact for any potential updates (unless, of course, you were considering changing it in an update.)

    I tried modifying the wp_register_scripts like so :

    
    		$scripts = array();
    		$scripts[] = array(
    			'handle' => 'acf-field-group',
    			'src' => $this->settings['dir'] . 'js/field-group.min.js',
    			'deps' => array('jquery'),
    			'in_footer' => true
    		);
    		$scripts[] = array(
    			'handle' => 'acf-input',
    			'src' => $this->settings['dir'] . 'js/input.min.js',
    			'deps' => array('jquery'),
    			'in_footer' => true
    		);
    		$scripts[] = array(
    			'handle' => 'acf-datepicker',
    			'src' => $this->settings['dir'] . 'core/fields/date_picker/jquery.ui.datepicker.js',
    			'deps' => array('jquery', 'acf-input'),
    			'in_footer' => true
    		);
    		
    		
    		foreach( $scripts as $script )
    		{
    			wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->settings['version'], $script['in_footer']);
    		}

    but I can’t find where they are enqueued. And it seems I’m looking in the wrong place as there is no jquery migrate here.

    • Elliot

    • November 12, 2013 at 4:28 pm

    Hi @mantismamita

    ACF does not include any jQuery migrate. It has a dependency for jQuery. Perhaps it is the WP core which is including the jQuery migrate? Or another plugin / theme?

  • Hi @elliot,
    Well that explains why I couldn’t find it but it seems to go away when I remove the add-ons folder. Any idea why the above bit of code doesn’t work to put jquery in the footer?

    Here is what I’m basing my findings on:

    PageSpeed Insights

    • Elliot

    • November 13, 2013 at 1:37 pm

    Hi @mantismamita

    Sorry, I don’t understand what you mean by the ‘add-ons’ folder. Can you shine some light on this?

    Thanks
    E

  • Ah sorry, I meant the acf “add-ons” which I put in a folder thus named:

    include_once('add-ons/acf-repeater/acf-repeater.php');
    include_once('add-ons/acf-gallery/acf-gallery.php');

    Thanks.

    • Elliot

    • November 14, 2013 at 4:07 pm

    Hi @mantismamita

    Can you comment out 1 of the add-ons? Which one includes the jQuery migrate code?
    What versions of each add-on are you using?

    Thanks
    E

  • Hi @elliot,
    It turns out that its another plugin that is putting jquery migrate in there. This is turning out to be a bit more complicated than I anticipated.
    I think I am just going to focus my energy on cacheing.

    To answer your question the add-ons are fairly recent. I think I bought them in October. Probably not old enough to warrant jquery migrate. I have included them in the theme so I’m a bit hesitant to update them even though I noticed there is an update available.

    Thanks so much for your help.

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.