Home › Forums › Add-ons › Repeater Field › 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?
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.
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.
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:
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.
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.
The topic ‘Putting jQuery in footer’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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.