Home Forums General Issues Folder for Javascript


Folder for Javascript

  • Could someone tell me what folder to place my Javascripts in order to call them from the acf/input/admin_enqueue_scripts action?

  • There is no folder where these will automatically be included from. You need to create you own admin_enqueue_scripts action and enqueue the scripts yourself and I would add the ACF script handle to the $dep argument when you enquieu them. Here is the ACF documentation on this

  • I’m still confused. In this page at WordPress, I see an example that looks like a path:

    <script type="text/javascript" src="/scripts/emailpage.js"></script>

    Are you saying that I register my script with a certain name, then put that name in the script below where it says ‘my-admin-js’?

    function my_admin_enqueue_scripts() {
    	wp_enqueue_script( 'my-admin-js', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
    add_action('admin_enqueue_scripts', 'my_admin_enqueue_scripts');
  • See the paragraph above that

    The safe and recommended method of adding JavaScript to a WordPress generated page, and WordPress Theme or Plugin, is by using wp_enqueue_script(). This function includes the script if it hasn’t already been included, and safely handles dependencies.

    While you can include JavaScript the other way it is not recommended. The main reason for this is because your script might depend on the ACF scripts being loaded first. This dependency can be handled by WP and it will make sure the scripts are loaded in the correct order by telling it what other scripts your script depends on In most cases when extending ACF with custom JS you’d want to use $deps = array('acf-field-group');

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

The topic ‘Folder for Javascript’ is closed to new replies.