0

I am using WordPress-Plugin-Boilerplate

In the plugins class-my-plugin-public.php I have the enqueue_scripts() function.

The ajax and the fabric load just fine. However if I load others below it will not insert into the page. Any ideas what I am doing wrong?

/**
 * Register the JavaScript for the public-facing side of the site.
 *
 * @since    1.0.0
 */
public function enqueue_scripts() {


    wp_localize_script( $this->plugin_name, 'canvas-draw' , array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );

    wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/fabric.min.js', array( 'jquery' ), $this->version, false );

    // This doesnt load
    wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/scroll-behaviour.js', array( 'jquery' ), $this->version, true );
    // This doesnt load either
    wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/drag-drop-index.min.js', array( 'jquery' ), $this->version, true );



}
1
  • 1
    Where do you specify the unique $handle as per - developer.wordpress.org/reference/functions/wp_enqueue_script - it appears like you are trying to reuse $this->plugin_name - here's the note from link above - If you try to register or enqueue an already registered handle with different parameters, the new parameters will be ignored. Instead, use wp_deregister_script() and register the script again with the new parameters. Commented Nov 24, 2017 at 15:22

2 Answers 2

2

You have to have unique $handle name for each script that you enqueue.

wp_enqueue_script( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

$handle (string) (Required) Name of the script. Should be unique.

You can do something like this:

/**
 * Register the JavaScript for the public-facing side of the site.
 *
 * @since    1.0.0
 */
public function enqueue_scripts() {


    wp_localize_script( $this->plugin_name, 'canvas-draw' , array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );

    wp_enqueue_script( $this->plugin_name . '_fabric', plugin_dir_url( __FILE__ ) . 'js/fabric.min.js', array( 'jquery' ), $this->version, false );

    wp_enqueue_script( $this->plugin_name . '_scroll-behaviour', plugin_dir_url( __FILE__ ) . 'js/scroll-behaviour.js', array( 'jquery' ), $this->version, true );

    wp_enqueue_script( $this->plugin_name . '_drag-drop-index', plugin_dir_url( __FILE__ ) . 'js/drag-drop-index.min.js', array( 'jquery' ), $this->version, true );

}
Sign up to request clarification or add additional context in comments.

Comments

0

Do you have a closing body tage </body> it might be the problem since wp appends the script just before it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.