Home › Forums › Front-end Issues › Load Javascript if acf_form is used
Hello,
I’m using some custom javascript for my acf frontend forms and was wondering if there is any way to load these scripts only when a page has an acf_form.
Are there any hooks I can attach my enque_scripts to?
Regards, Chris
Enqueue your custom JS and CSS on the hook acf/input/admin_enqueue_scripts
.
Thanks John! I’ve seen this hook, but thought it would only work in wp-admin.
That hook, as I’ve discovered, is run whenever ACF field groups are included on a page, front end or back. Figured it out when I was creating a custom field type and couldn’t get it to work with acf_form().
Hi can you help me with this HOOK.
I want to load specific JS and CSS if there is a specific flexible content on my page and i don’t understand how to use it.
Thanks.
Simon.
This would not be the hook you’d want to use. This is for adding scripts and/or styles to alter the way that ACF fields work.
The hooks and functions you’re looking for are
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts
https://developer.wordpress.org/reference/functions/wp_enqueue_style/
https://developer.wordpress.org/reference/functions/wp_enqueue_script/
I need to write something like that for the css ?
function themeslug_enqueue_style() {
if ( get_sub_field(‘slider’) ) {
wp_enqueue_style( ‘parent-stylesheet’, trailingslashit( get_template_directory_uri() ) . ‘style.css’, false );
}
}
add_action( ‘wp_enqueue_scripts’, ‘themeslug_enqueue_style’ );
The topic ‘Load Javascript if acf_form is used’ 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.