Yassine amri
Yassine amri

Reputation: 13

Wordpress ACF Include input.js not working

I'm using acf v4 plugin for wordpress. I'm trying to include the input.js. This is the code that i added

function input_admin_enqueue_scripts()
    {
        // Note: This function can be removed if not used


        // register ACF scripts
        wp_register_script( 'acf-input-progressbar', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version'] );
        wp_register_style( 'acf-input-progressbar', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version'] ); 


        // scripts
        wp_enqueue_script(array(
            'acf-input-progressbar',    
        ));

        // styles
        wp_enqueue_style(array(
            'acf-input-progressbar',    
        ));


    }

But the javascript is never called. I added the console.log function to test the call :

(function($){

    console.log("Test input.hs");

....

This is the name that i used for my plugin : acf-progressbar

Files :

Upvotes: 1

Views: 1454

Answers (1)

SufferMyJoy
SufferMyJoy

Reputation: 304

You have to hook in your function with something like the following:

add_action( 'admin_enqueue_scripts', 'input_admin_enqueue_scripts' );

The above call will enqueue the script on the admin side of WordPress which is what I assume you want due to the function name. If you want to enqueue them everywhere then use this instead:

add_action( 'wp_enqueue_scripts', 'input_admin_enqueue_scripts' );

The calls to add_action need to take place in the global space. So in the end you'll have something like:

function input_admin_enqueue_scripts() {
    // Note: This function can be removed if not used
    // register ACF scripts
    wp_register_script( 'acf-input-progressbar', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version'] );
    wp_register_style( 'acf-input-progressbar', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version'] ); 

    // scripts
    wp_enqueue_script(array(
        'acf-input-progressbar',    
    ));

    // styles
    wp_enqueue_style(array(
        'acf-input-progressbar',    
    ));
}
add_action( 'admin_enqueue_scripts', 'input_admin_enqueue_scripts' );

If you already have your function hooked in with a call to add_action then the problem is probably that you have your style and script named the same:

wp_register_script( 'acf-input-progressbar' ...
wp_register_style( 'acf-input-progressbar', ...

I would switch these to the following and see if that works:

wp_register_script( 'acf-input-progressbar-js' ...
wp_register_style( 'acf-input-progressbar-css', ...

Upvotes: 3

Related Questions